From a5af3f75af86ff0abd9964bfd69483d116c12b13 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 22 Sep 2007 17:08:09 +0000 Subject: [PATCH] Added symbols as a legal way of specifying plugins in config.plugins (closes #9629) [tom] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7540 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/CHANGELOG | 2 ++ railties/lib/initializer.rb | 5 ++++- railties/lib/rails/plugin/loader.rb | 6 +++--- railties/test/plugin_locator_test.rb | 20 +++++++++++++------- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 0b453b34aa..bfa37aaf0f 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -5,6 +5,8 @@ # Loads :classic_pagination before all the other plugins config.plugins = [ :classic_pagination, :all ] +* Added symbols as a legal way of specifying plugins in config.plugins #9629 [tom] + * Removed deprecated task names, like clear_logs, in favor of the new namespaced style [DHH] * Support multiple config.after_initialize blocks so plugins and apps can more easily cooperate. #9582 [zdennis] diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 111b5237ba..3183b0a34a 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -429,7 +429,10 @@ class Configuration # The list of plugins to load. If this is set to nil, all plugins will # be loaded. If this is set to [], no plugins will be loaded. Otherwise, # plugins will be loaded in the order specified. - attr_accessor :plugins + attr_reader :plugins + def plugins=(plugins) + @plugins = plugins.nil? ? nil : plugins.map { |p| p.to_sym } + end # The path to the root of the plugins directory. By default, it is in # vendor/plugins. diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index e935f9b34b..016bcc6c50 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -13,7 +13,7 @@ def load(*args) def initialize(initializer, directory) @initializer = initializer @directory = directory - @name = File.basename(directory) + @name = File.basename(directory).to_sym end def load @@ -126,7 +126,7 @@ def <=>(other_plugin_loader) end if !explicitly_enabled? && !other_plugin_loader.explicitly_enabled? - name <=> other_plugin_loader.name + 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? ? @@ -138,7 +138,7 @@ def <=>(other_plugin_loader) end else - name <=> other_plugin_loader.name + name.to_s <=> other_plugin_loader.name.to_s end end end diff --git a/railties/test/plugin_locator_test.rb b/railties/test/plugin_locator_test.rb index cf6c0d9507..3ac4493d47 100644 --- a/railties/test/plugin_locator_test.rb +++ b/railties/test/plugin_locator_test.rb @@ -16,33 +16,39 @@ def test_no_plugins_are_loaded_if_the_configuration_has_an_empty_plugin_list end def test_only_the_specified_plugins_are_located_in_the_order_listed - plugin_names = %w(stubby acts_as_chunky_bacon) + plugin_names = [:stubby, :acts_as_chunky_bacon] only_load_the_following_plugins! plugin_names 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 + assert_equal [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @locator.plugin_names, failure_tip end def test_all_plugins_loaded_when_all_is_used - plugin_names = ['stubby', 'acts_as_chunky_bacon', :all] + plugin_names = [:stubby, :acts_as_chunky_bacon, :all] only_load_the_following_plugins! plugin_names failure_tip = "It's likely someone has added a new plugin fixture without updating this list" - assert_equal %w(stubby acts_as_chunky_bacon a plugin_with_no_lib_dir), @locator.plugin_names, failure_tip + assert_equal [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @locator.plugin_names, failure_tip end def test_all_plugins_loaded_after_all - plugin_names = ['stubby', :all, 'acts_as_chunky_bacon'] + plugin_names = [:stubby, :all, :acts_as_chunky_bacon] only_load_the_following_plugins! plugin_names failure_tip = "It's likely someone has added a new plugin fixture without updating this list" - assert_equal %w(stubby a plugin_with_no_lib_dir acts_as_chunky_bacon ), @locator.plugin_names, failure_tip + assert_equal [:stubby, :a, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @locator.plugin_names, failure_tip end + def test_plugin_names_may_be_strings + plugin_names = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] + only_load_the_following_plugins! plugin_names + failure_tip = "It's likely someone has added a new plugin fixture without updating this list" + assert_equal [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @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) + only_load_the_following_plugins! [:stubby, :acts_as_a_non_existant_plugin] assert_raises(LoadError) do @initializer.load_plugins end -- GitLab