mirror of
https://github.com/github/rails.git
synced 2026-04-04 03:00:58 -04:00
Move responsibility for ensuring that all registered gems were loaded from the FileSystemLocator into the Initializer once all locators have had a chance to load the gems they located. [Marcel Molina Jr.]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6292 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -192,6 +192,7 @@ module Rails
|
||||
plugin.load
|
||||
end
|
||||
end
|
||||
ensure_all_registered_plugins_are_loaded!
|
||||
$LOAD_PATH.uniq!
|
||||
end
|
||||
|
||||
@@ -339,6 +340,16 @@ module Rails
|
||||
load(initializer)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def ensure_all_registered_plugins_are_loaded!
|
||||
unless configuration.plugins.nil?
|
||||
unless loaded_plugins == configuration.plugins
|
||||
missing_plugins = configuration.plugins - loaded_plugins
|
||||
raise LoadError, "Could not locate the following plugins: #{missing_plugins.to_sentence}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# The Configuration class holds all the parameters for the Initializer and
|
||||
|
||||
@@ -29,27 +29,11 @@ module Rails
|
||||
class FileSystemLocator < Locator
|
||||
private
|
||||
def located_plugins
|
||||
returning locate_plugins do |loaders|
|
||||
ensure_all_registered_plugins_are_loaded!(loaders)
|
||||
end
|
||||
end
|
||||
|
||||
def locate_plugins
|
||||
initializer.configuration.plugin_paths.flatten.inject([]) do |plugins, path|
|
||||
plugins.concat locate_plugins_under(path)
|
||||
plugins
|
||||
end.flatten
|
||||
end
|
||||
|
||||
def ensure_all_registered_plugins_are_loaded!(loaders)
|
||||
registered_plugins = initializer.configuration.plugins
|
||||
unless registered_plugins.nil? || registered_plugins.empty?
|
||||
missing_plugins = registered_plugins - loaders.map(&:name)
|
||||
unless missing_plugins.empty?
|
||||
raise LoadError, "Could not locate the following plugins: #{missing_plugins.to_sentence}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# This starts at the base path looking for directories that pass the plugin_path? test of the Plugin::Loader.
|
||||
# Since plugins can be nested arbitrarily deep within an unspecified number of intermediary directories,
|
||||
|
||||
@@ -21,21 +21,21 @@ class TestPluginFileSystemLocator < Test::Unit::TestCase
|
||||
assert_equal plugin_names, @locator.plugin_names
|
||||
end
|
||||
|
||||
def test_registering_a_plugin_name_that_does_not_exist_raises_a_load_error
|
||||
only_load_the_following_plugins! %w(stubby acts_as_a_non_existant_plugin)
|
||||
assert_raises(LoadError) do
|
||||
@locator.plugins
|
||||
end
|
||||
end
|
||||
|
||||
def test_all_plugins_are_loaded_when_registered_plugin_list_is_untouched
|
||||
failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
|
||||
assert_equal %w(a acts_as_chunky_bacon plugin_with_no_lib_dir stubby), @locator.plugin_names, failure_tip
|
||||
end
|
||||
|
||||
|
||||
def test_registering_a_plugin_name_that_does_not_exist_raises_a_load_error
|
||||
only_load_the_following_plugins! %w(stubby acts_as_a_non_existant_plugin)
|
||||
assert_raises(LoadError) do
|
||||
@initializer.load_plugins
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def new_locator(initializer = @initializer)
|
||||
Rails::Plugin::FileSystemLocator.new(initializer)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user