aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/lib/initializer.rb29
-rw-r--r--railties/test/plugin_test.rb37
3 files changed, 58 insertions, 10 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index 0b34532801..ce2f2b0611 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Make config.plugins affect the load path and the dependencies system. Allows you to control plugin loading order, and keep disabled plugins off the load path. [James Adam]
+
* Don't generate a components directory in new Rails apps. [Jeremy Kemper]
* Fixed script/process/spawner to work properly with Mongrel including in -r (daemonize mode) [DHH]
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index 908dde71c2..5b529ffc3d 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -48,7 +48,7 @@ module Rails
# instance.
def initialize(configuration)
@configuration = configuration
- @loaded_plugins = Set.new
+ @loaded_plugins = []
end
# Sequentially step through all of the available initialization routines,
@@ -176,9 +176,22 @@ module Rails
# * evaluate <tt>init.rb</tt> if present
#
# After all plugins are loaded, duplicates are removed from the load path.
- # Plugins are loaded in alphabetical order.
+ # If an array of plugin names is specified in config.plugins, the plugins
+ # will be loaded in that order. Otherwise, plugins are loaded in alphabetical
+ # order.
def load_plugins
- find_plugins(configuration.plugin_paths).sort.each { |path| load_plugin path }
+ if configuration.plugins.nil?
+ # a nil value implies we don't care about plugins; load 'em all in a reliable order
+ find_plugins(configuration.plugin_paths).sort.each { |path| load_plugin path }
+ elsif !configuration.plugins.empty?
+ # we've specified a config.plugins array, so respect that order
+ plugin_paths = find_plugins(configuration.plugin_paths)
+ configuration.plugins.each do |name|
+ path = plugin_paths.find { |p| File.basename(p) == name }
+ raise(LoadError, "Cannot find the plugin '#{name}'!") if path.nil?
+ load_plugin path
+ end
+ end
$LOAD_PATH.uniq!
end
@@ -345,7 +358,7 @@ module Rails
end
def plugin_enabled?(path)
- configuration.plugins.empty? || configuration.plugins.include?(File.basename(path))
+ configuration.plugins.nil? || configuration.plugins.include?(File.basename(path))
end
# Load the plugin at <tt>path</tt> unless already loaded.
@@ -374,6 +387,7 @@ module Rails
if has_lib
application_lib_index = $LOAD_PATH.index(File.join(RAILS_ROOT, "lib")) || 0
$LOAD_PATH.insert(application_lib_index + 1, lib_path)
+ Dependencies.load_paths << lib_path
end
# Allow plugins to reference the current configuration object
@@ -470,7 +484,9 @@ module Rails
# any method of +nil+. Set to +false+ for the standard Ruby behavior.
attr_accessor :whiny_nils
- # The list of plugins to load. If this is set to <tt>[]</tt>, all plugins will be loaded.
+ # The list of plugins to load. If this is set to <tt>nil</tt>, all plugins will
+ # be loaded. If this is set to <tt>[]</tt>, no plugins will be loaded. Otherwise,
+ # plugins will be loaded in the order specified.
attr_accessor :plugins
# The path to the root of the plugins directory. By default, it is in
@@ -592,7 +608,6 @@ module Rails
vendor
).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
- paths.concat Dir["#{root_path}/vendor/plugins/*/lib/"]
paths.concat builtin_directories
end
@@ -642,7 +657,7 @@ module Rails
end
def default_plugins
- []
+ nil
end
def default_plugin_paths
diff --git a/railties/test/plugin_test.rb b/railties/test/plugin_test.rb
index 5ab1e15414..f46f1db615 100644
--- a/railties/test/plugin_test.rb
+++ b/railties/test/plugin_test.rb
@@ -43,7 +43,7 @@ class PluginTest < Test::Unit::TestCase
def test_load_plugin
stubby = "#{File.dirname(__FILE__)}/fixtures/plugins/default/stubby"
- expected = Set.new(['stubby'])
+ expected = ['stubby']
assert @init.send(:load_plugin, stubby)
assert_equal expected, @init.loaded_plugins
@@ -66,10 +66,41 @@ class PluginTest < Test::Unit::TestCase
def test_load_plugins_from_two_sources
assert_loaded_plugins %w(a stubby acts_as_chunky_bacon), ['default', 'alternate']
end
+
+ def test_load_all_plugins_when_config_plugins_is_nil
+ @init.configuration.plugins = nil
+ assert_loaded_plugins %w(a stubby acts_as_chunky_bacon), ['default', 'alternate']
+ end
+
+ def test_load_no_plugins_when_config_plugins_is_empty_array
+ @init.configuration.plugins = []
+ assert_loaded_plugins [], ['default', 'alternate']
+ end
+
+ def test_load_only_selected_plugins
+ plugins = %w(stubby a)
+ @init.configuration.plugins = plugins
+ assert_loaded_plugins plugins, ['default', 'alternate']
+ end
+
+ def test_load_plugins_in_order
+ plugins = %w(stubby acts_as_chunky_bacon a)
+ @init.configuration.plugins = plugins
+ assert_plugin_load_order plugins, ['default', 'alternate']
+ end
+ def test_raise_error_when_plugin_not_found
+ @init.configuration.plugins = %w(this_plugin_does_not_exist)
+ assert_raise(LoadError) { load_plugins(['default', 'alternate']) }
+ end
+
protected
- def assert_loaded_plugins(plugins, path)
- assert_equal Set.new(plugins), load_plugins(path)
+ def assert_loaded_plugins(plugins, paths)
+ assert_equal plugins.sort, load_plugins(paths).sort
+ end
+
+ def assert_plugin_load_order(plugins, paths)
+ assert_equal plugins, load_plugins(paths)
end
def load_plugins(*paths)