diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-03-27 17:47:51 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-03-27 17:47:51 +0000 |
commit | f5b991d76dc5d21f1870da067fb3101440256fba (patch) | |
tree | df48a8e0358a8e8767dfe4f613e76016f0206e2d /railties/lib/rails | |
parent | 35d3ede97447d70aae8db716cd2448f116014d68 (diff) | |
download | rails-f5b991d76dc5d21f1870da067fb3101440256fba.tar.gz rails-f5b991d76dc5d21f1870da067fb3101440256fba.tar.bz2 rails-f5b991d76dc5d21f1870da067fb3101440256fba.zip |
Added Plugin#about method to programmatically access the about.yml in a plugin (closes #10979) [lazyatom]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9098 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib/rails')
-rw-r--r-- | railties/lib/rails/plugin.rb | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index be392195d4..03fa309ca3 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -1,5 +1,4 @@ module Rails - # The Plugin class should be an object which provides the following methods: # # * +name+ - used during initialisation to order the plugin (based on name and @@ -11,6 +10,12 @@ module Rails # These methods are expected by the Rails::Plugin::Locator and Rails::Plugin::Loader classes. # The default implementation returns the <tt>lib</tt> directory as its </tt>load_paths</tt>, # and evaluates <tt>init.rb</tt> when <tt>load</tt> is called. + # + # You can also inspect the about.yml data programmatically: + # + # plugin = Rails::Plugin.new(path_to_my_plugin) + # plugin.about["author"] # => "James Adam" + # plugin.about["url"] # => "http://interblah.net" class Plugin include Comparable @@ -18,8 +23,8 @@ module Rails def initialize(directory) @directory = directory - @name = File.basename(@directory) rescue nil - @loaded = false + @name = File.basename(@directory) rescue nil + @loaded = false end def valid? @@ -47,8 +52,19 @@ module Rails def <=>(other_plugin) name <=> other_plugin.name end + + def about + @about ||= load_about_information + end private + def load_about_information + about_yml_path = File.join(@directory, "about.yml") + parsed_yml = File.exist?(about_yml_path) ? YAML.load(File.read(about_yml_path)) : {} + parsed_yml || {} + rescue Exception + {} + end def report_nonexistant_or_empty_plugin! raise LoadError, "Can not find the plugin named: #{name}" |