| Class | Rails::Plugin::Loader |
| In: |
railties/lib/rails/plugin/loader.rb
|
| Parent: | Object |
| directory | [R] | |
| initializer | [R] | |
| name | [R] |
# File railties/lib/rails/plugin/loader.rb, line 13 def initialize(initializer, directory) @initializer = initializer @directory = directory @name = File.basename(directory).to_sym end
# File railties/lib/rails/plugin/loader.rb, line 36 def enabled? !explicit_plugin_loading_order? || registered? end
# File railties/lib/rails/plugin/loader.rb, line 40 def explicitly_enabled? !explicit_plugin_loading_order? || explicitly_registered? end
# File railties/lib/rails/plugin/loader.rb, line 48 def explicitly_registered? explicit_plugin_loading_order? && registered_plugins.include?(name) end
# File railties/lib/rails/plugin/loader.rb, line 19 def load return false if loaded? report_nonexistant_or_empty_plugin! add_to_load_path! register_plugin_as_loaded evaluate true end
# File railties/lib/rails/plugin/loader.rb, line 28 def loaded? initializer.loaded_plugins.include?(name) end
# File railties/lib/rails/plugin/loader.rb, line 52 def plugin_does_not_exist!(plugin_name = name) raise LoadError, "Can not find the plugin named: #{plugin_name}" end
# File railties/lib/rails/plugin/loader.rb, line 32 def plugin_path? File.directory?(directory) && (has_lib_directory? || has_init_file?) end
# File railties/lib/rails/plugin/loader.rb, line 44 def registered? explicit_plugin_loading_order? && registered_plugins_names_plugin?(name) end
# File railties/lib/rails/plugin/loader.rb, line 122 def <=>(other_plugin_loader) if explicit_plugin_loading_order? if non_existent_plugin = [self, other_plugin_loader].detect { |plugin| !registered_plugins_names_plugin?(plugin.name) } plugin_does_not_exist!(non_existent_plugin.name) end if !explicitly_enabled? && !other_plugin_loader.explicitly_enabled? name.to_s <=> other_plugin_loader.name.to_s elsif registered_plugins.include?(:all) && (!explicitly_enabled? || !other_plugin_loader.explicitly_enabled?) effective_index = explicitly_enabled? ? registered_plugins.index(name) : registered_plugins.index(:all) other_effective_index = other_plugin_loader.explicitly_enabled? ? registered_plugins.index(other_plugin_loader.name) : registered_plugins.index(:all) effective_index <=> other_effective_index else registered_plugins.index(name) <=> registered_plugins.index(other_plugin_loader.name) end else name.to_s <=> other_plugin_loader.name.to_s end end
# File railties/lib/rails/plugin/loader.rb, line 93 def add_to_load_path! # Add lib to load path *after* the application lib, to allow # application libraries to override plugin libraries. if has_lib_directory? application_lib_index = $LOAD_PATH.index(application_library_path) || 0 $LOAD_PATH.insert(application_lib_index + 1, lib_path) Dependencies.load_paths << lib_path Dependencies.load_once_paths << lib_path end end
# File railties/lib/rails/plugin/loader.rb, line 104 def application_library_path File.join(RAILS_ROOT, 'lib') end
Allow plugins to reference the current configuration object
# File railties/lib/rails/plugin/loader.rb, line 109 def config initializer.configuration end
Evaluate in init.rb
# File railties/lib/rails/plugin/loader.rb, line 118 def evaluate silence_warnings { eval(IO.read(init_path), binding, init_path) } if has_init_file? end
# File railties/lib/rails/plugin/loader.rb, line 69 def explicit_plugin_loading_order? !registered_plugins.nil? end
# File railties/lib/rails/plugin/loader.rb, line 85 def has_lib_directory? File.directory?(lib_path) end
# File railties/lib/rails/plugin/loader.rb, line 81 def init_path File.join(directory, 'init.rb') end
# File railties/lib/rails/plugin/loader.rb, line 113 def register_plugin_as_loaded initializer.loaded_plugins << name end
The plugins that have been explicitly listed with config.plugins. If this list is nil then it means the client does not care which plugins or in what order they are loaded, so we load all in alphabetical order. If it is an empty array, we load no plugins, if it is non empty, we load the named plugins in the order specified.
# File railties/lib/rails/plugin/loader.rb, line 61 def registered_plugins config.plugins end
# File railties/lib/rails/plugin/loader.rb, line 65 def registered_plugins_names_plugin?(plugin_name) registered_plugins.include?(plugin_name) || registered_plugins.include?(:all) end