提交 9f53e09e 编写于 作者: M Marcel Molina

Move responsibility for ensuring that all registered gems were loaded from the...

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
上级 3d2c232d
......@@ -192,6 +192,7 @@ def load_plugins
plugin.load
end
end
ensure_all_registered_plugins_are_loaded!
$LOAD_PATH.uniq!
end
......@@ -339,6 +340,16 @@ def load_application_initializers
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 @@ def located_plugins
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 @@ def test_only_the_specified_plugins_are_located_in_the_order_listed
assert_equal plugin_names, @locator.plugin_names
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
@locator.plugins
@initializer.load_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
private
def new_locator(initializer = @initializer)
Rails::Plugin::FileSystemLocator.new(initializer)
end
end
end
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册