Class: Rails::Plugin::Loader
Instance Attribute Summary collapse
-
#initializer ⇒ Object
readonly
Returns the value of attribute initializer.
Instance Method Summary collapse
-
#add_plugin_load_paths ⇒ Object
Adds the load paths for every plugin into the $LOAD_PATH.
-
#all_plugins ⇒ Object
Returns all the plugins that could be found by the current locators.
-
#initialize(initializer) ⇒ Loader
constructor
Creates a new Plugin::Loader instance, associated with the given Rails::Initializer.
- #load_plugins ⇒ Object
-
#plugins ⇒ Object
Returns the plugins to be loaded, in the order they should be loaded.
Constructor Details
#initialize(initializer) ⇒ Loader
Creates a new Plugin::Loader instance, associated with the given Rails::Initializer. This default implementation automatically locates all plugins, and adds all plugin load paths, when it is created. The plugins are then fully loaded (init.rb is evaluated) when load_plugins is called.
It is the loader’s responsibility to ensure that only the plugins specified in the configuration are actually loaded, and that the order defined is respected.
16 17 18 |
# File 'lib/rails/plugin/loader.rb', line 16 def initialize(initializer) @initializer = initializer end |
Instance Attribute Details
#initializer ⇒ Object (readonly)
Returns the value of attribute initializer.
6 7 8 |
# File 'lib/rails/plugin/loader.rb', line 6 def initializer @initializer end |
Instance Method Details
#add_plugin_load_paths ⇒ Object
Adds the load paths for every plugin into the $LOAD_PATH. Plugin load paths are added after the application’s lib
directory, to ensure that an application can always override code within a plugin.
Plugin load paths are also added to Dependencies.load_paths, and Dependencies.load_once_paths.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rails/plugin/loader.rb', line 44 def add_plugin_load_paths plugins.each do |plugin| plugin.load_paths.each do |path| $LOAD_PATH.insert(application_lib_index + 1, path) ActiveSupport::Dependencies.load_paths << path unless Rails.configuration.reload_plugins? ActiveSupport::Dependencies.load_once_paths << path end end end $LOAD_PATH.uniq! end |
#all_plugins ⇒ Object
Returns all the plugins that could be found by the current locators.
26 27 28 29 |
# File 'lib/rails/plugin/loader.rb', line 26 def all_plugins @all_plugins ||= locate_plugins @all_plugins end |
#load_plugins ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/rails/plugin/loader.rb', line 31 def load_plugins plugins.each do |plugin| plugin.load(initializer) register_plugin_as_loaded(plugin) end ensure_all_registered_plugins_are_loaded! end |
#plugins ⇒ Object
Returns the plugins to be loaded, in the order they should be loaded.
21 22 23 |
# File 'lib/rails/plugin/loader.rb', line 21 def plugins @plugins ||= all_plugins.select { |plugin| should_load?(plugin) }.sort { |p1, p2| order_plugins(p1, p2) } end |