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.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rails/plugin/loader.rb', line 52

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 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.



31
32
33
34
# File 'lib/rails/plugin/loader.rb', line 31

def all_plugins
  @all_plugins ||= locate_plugins
  @all_plugins
end

#engine_metal_pathsObject



68
69
70
# File 'lib/rails/plugin/loader.rb', line 68

def engine_metal_paths
  engines.collect(&:metal_path)
end

#enginesObject

Returns the plugins that are in engine-form (have an app/ directory)



26
27
28
# File 'lib/rails/plugin/loader.rb', line 26

def engines
  @engines ||= plugins.select(&:engine?)
end

#load_pluginsObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/rails/plugin/loader.rb', line 36

def load_plugins
  plugins.each do |plugin|
    plugin.load(initializer)
    register_plugin_as_loaded(plugin)
  end

  configure_engines

  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