Class: Rails::Plugin
- Includes:
- Comparable
- Defined in:
- lib/rails/plugin.rb,
lib/rails/plugin/loader.rb,
lib/rails/plugin/locator.rb
Overview
The Plugin class should be an object which provides the following methods:
-
name
- Used during initialisation to order the plugin (based on name andthe 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"
Direct Known Subclasses
Defined Under Namespace
Classes: FileSystemLocator, GemLocator, Loader, Locator
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #<=>(other_plugin) ⇒ Object
- #about ⇒ Object
- #controller_path ⇒ Object
-
#engine? ⇒ Boolean
Engines are plugins with an app/ directory.
-
#initialize(directory) ⇒ Plugin
constructor
A new instance of Plugin.
-
#load(initializer) ⇒ Object
Evaluates a plugin’s init.rb file.
-
#load_paths ⇒ Object
Returns a list of paths this plugin wishes to make available in
$LOAD_PATH
. - #loaded? ⇒ Boolean
- #locale_files ⇒ Object
- #locale_path ⇒ Object
-
#localized? ⇒ Boolean
Returns true if there is any localization file in locale_path.
- #metal_path ⇒ Object
-
#routed? ⇒ Boolean
Returns true if the engine ships with a routing file.
- #routing_file ⇒ Object
- #valid? ⇒ Boolean
- #view_path ⇒ Object
Constructor Details
#initialize(directory) ⇒ Plugin
Returns a new instance of Plugin.
24 25 26 27 28 |
# File 'lib/rails/plugin.rb', line 24 def initialize(directory) @directory = directory @name = File.basename(@directory) rescue nil @loaded = false end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
22 23 24 |
# File 'lib/rails/plugin.rb', line 22 def directory @directory end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/rails/plugin.rb', line 22 def name @name end |
Instance Method Details
#<=>(other_plugin) ⇒ Object
56 57 58 |
# File 'lib/rails/plugin.rb', line 56 def <=>(other_plugin) name <=> other_plugin.name end |
#about ⇒ Object
60 61 62 |
# File 'lib/rails/plugin.rb', line 60 def about @about ||= load_about_information end |
#controller_path ⇒ Object
83 84 85 |
# File 'lib/rails/plugin.rb', line 83 def controller_path File.join(directory, 'app', 'controllers') end |
#engine? ⇒ Boolean
Engines are plugins with an app/ directory.
65 66 67 |
# File 'lib/rails/plugin.rb', line 65 def engine? has_app_directory? end |
#load(initializer) ⇒ Object
Evaluates a plugin’s init.rb file.
45 46 47 48 49 50 |
# File 'lib/rails/plugin.rb', line 45 def load(initializer) return if loaded? report_nonexistant_or_empty_plugin! unless valid? evaluate_init_rb(initializer) @loaded = true end |
#load_paths ⇒ Object
Returns a list of paths this plugin wishes to make available in $LOAD_PATH
.
35 36 37 38 39 40 41 42 |
# File 'lib/rails/plugin.rb', line 35 def load_paths report_nonexistant_or_empty_plugin! unless valid? [].tap do |load_paths| load_paths << lib_path if has_lib_directory? load_paths << app_paths if has_app_directory? end.flatten end |
#loaded? ⇒ Boolean
52 53 54 |
# File 'lib/rails/plugin.rb', line 52 def loaded? @loaded end |
#locale_files ⇒ Object
99 100 101 |
# File 'lib/rails/plugin.rb', line 99 def locale_files Dir[ File.join(locale_path, '*.{rb,yml}') ] end |
#locale_path ⇒ Object
95 96 97 |
# File 'lib/rails/plugin.rb', line 95 def locale_path File.join(directory, 'config', 'locales') end |
#localized? ⇒ Boolean
Returns true if there is any localization file in locale_path
75 76 77 |
# File 'lib/rails/plugin.rb', line 75 def localized? locale_files.any? end |
#metal_path ⇒ Object
87 88 89 |
# File 'lib/rails/plugin.rb', line 87 def File.join(directory, 'app', 'metal') end |
#routed? ⇒ Boolean
Returns true if the engine ships with a routing file
70 71 72 |
# File 'lib/rails/plugin.rb', line 70 def routed? File.exist?(routing_file) end |
#routing_file ⇒ Object
91 92 93 |
# File 'lib/rails/plugin.rb', line 91 def routing_file File.join(directory, 'config', 'routes.rb') end |
#valid? ⇒ Boolean
30 31 32 |
# File 'lib/rails/plugin.rb', line 30 def valid? File.directory?(directory) && (has_app_directory? || has_lib_directory? || has_init_file?) end |
#view_path ⇒ Object
79 80 81 |
# File 'lib/rails/plugin.rb', line 79 def view_path File.join(directory, 'app', 'views') end |