Class: Rails::Plugin::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/plugin/loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#initializerObject (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_pathsObject

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_pluginsObject

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_pluginsObject



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

#pluginsObject

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