The Plugin class should be an object which provides the following methods:
- name - Used during initialisation to order the plugin (based on
name and
the contents of <tt>config.plugins</tt>). - +valid?+ - Returns true if this plugin can be loaded.
- load_paths - Each path within the returned array will be added to the $LOAD_PATH.
- load - Finally ‘load’ the plugin.
These methods are expected by the Rails::Plugin::Locator and Rails::Plugin::Loader classes. The default implementation returns the lib directory as its load_paths, and evaluates init.rb when load 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"
- <=>
- about
- controller_path
- engine?
- load
- load_paths
- loaded?
- locale_files
- locale_path
- localized?
- metal_path
- new
- routed?
- routing_file
- valid?
- view_path
- Comparable
| [R] | directory | |
| [R] | name |
[ show source ]
# File railties/lib/rails/plugin.rb, line 24
24: def initialize(directory)
25: @directory = directory
26: @name = File.basename(@directory) rescue nil
27: @loaded = false
28: end
[ show source ]
# File railties/lib/rails/plugin.rb, line 56
56: def <=>(other_plugin)
57: name <=> other_plugin.name
58: end
[ show source ]
# File railties/lib/rails/plugin.rb, line 60
60: def about
61: @about ||= load_about_information
62: end
[ show source ]
# File railties/lib/rails/plugin.rb, line 83
83: def controller_path
84: File.join(directory, 'app', 'controllers')
85: end
Engines are plugins with an app/ directory.
[ show source ]
# File railties/lib/rails/plugin.rb, line 65
65: def engine?
66: has_app_directory?
67: end
Evaluates a plugin‘s init.rb file.
[ show source ]
# File railties/lib/rails/plugin.rb, line 45
45: def load(initializer)
46: return if loaded?
47: report_nonexistant_or_empty_plugin! unless valid?
48: evaluate_init_rb(initializer)
49: @loaded = true
50: end
Returns a list of paths this plugin wishes to make available in $LOAD_PATH.
[ show source ]
# File railties/lib/rails/plugin.rb, line 35
35: def load_paths
36: report_nonexistant_or_empty_plugin! unless valid?
37:
38: returning [] do |load_paths|
39: load_paths << lib_path if has_lib_directory?
40: load_paths << app_paths if has_app_directory?
41: end.flatten
42: end
[ show source ]
# File railties/lib/rails/plugin.rb, line 52
52: def loaded?
53: @loaded
54: end
[ show source ]
# File railties/lib/rails/plugin.rb, line 99
99: def locale_files
100: Dir[ File.join(locale_path, '*.{rb,yml}') ]
101: end
[ show source ]
# File railties/lib/rails/plugin.rb, line 95
95: def locale_path
96: File.join(directory, 'config', 'locales')
97: end
Returns true if there is any localization file in locale_path
[ show source ]
# File railties/lib/rails/plugin.rb, line 75
75: def localized?
76: locale_files.any?
77: end
[ show source ]
# File railties/lib/rails/plugin.rb, line 87
87: def metal_path
88: File.join(directory, 'app', 'metal')
89: end
Returns true if the engine ships with a routing file
[ show source ]
# File railties/lib/rails/plugin.rb, line 70
70: def routed?
71: File.exist?(routing_file)
72: end
[ show source ]
# File railties/lib/rails/plugin.rb, line 91
91: def routing_file
92: File.join(directory, 'config', 'routes.rb')
93: end
[ show source ]
# File railties/lib/rails/plugin.rb, line 30
30: def valid?
31: File.directory?(directory) && (has_app_directory? || has_lib_directory? || has_init_file?)
32: end
[ show source ]
# File railties/lib/rails/plugin.rb, line 79
79: def view_path
80: File.join(directory, 'app', 'views')
81: end