Ticket #6851: load_plugins_in_specified_order.patch
| File load_plugins_in_specified_order.patch, 4.2 kB (added by lazyatom, 2 years ago) |
|---|
-
test/plugin_test.rb
old new 43 43 44 44 def test_load_plugin 45 45 stubby = "#{File.dirname(__FILE__)}/fixtures/plugins/default/stubby" 46 expected = Set.new(['stubby'])46 expected = ['stubby'] 47 47 48 48 assert @init.send(:load_plugin, stubby) 49 49 assert_equal expected, @init.loaded_plugins … … 66 66 def test_load_plugins_from_two_sources 67 67 assert_loaded_plugins %w(a stubby acts_as_chunky_bacon), ['default', 'alternate'] 68 68 end 69 70 def test_load_all_plugins_when_config_plugins_is_nil 71 @init.configuration.plugins = nil 72 assert_loaded_plugins %w(a stubby acts_as_chunky_bacon), ['default', 'alternate'] 73 end 69 74 75 def test_load_no_plugins_when_config_plugins_is_empty_array 76 @init.configuration.plugins = [] 77 assert_loaded_plugins [], ['default', 'alternate'] 78 end 79 80 def test_load_only_selected_plugins 81 plugins = %w(stubby a) 82 @init.configuration.plugins = plugins 83 assert_loaded_plugins plugins, ['default', 'alternate'] 84 end 85 86 def test_load_plugins_in_order 87 plugins = %w(stubby acts_as_chunky_bacon a) 88 @init.configuration.plugins = plugins 89 assert_plugin_load_order plugins, ['default', 'alternate'] 90 end 91 70 92 protected 71 93 def assert_loaded_plugins(plugins, path) 72 assert_equal Set.new(plugins), load_plugins(path)94 assert_equal plugins.sort, load_plugins(path).sort 73 95 end 96 97 def assert_plugin_load_order(plugins, path) 98 assert_equal plugins, load_plugins(path) 99 end 74 100 75 101 def load_plugins(*paths) 76 102 @init.configuration.plugin_paths = paths.flatten.map { |p| "#{File.dirname(__FILE__)}/fixtures/plugins/#{p}" } -
lib/initializer.rb
old new 48 48 # instance. 49 49 def initialize(configuration) 50 50 @configuration = configuration 51 @loaded_plugins = Set.new51 @loaded_plugins = [] 52 52 end 53 53 54 54 # Sequentially step through all of the available initialization routines, … … 176 176 # * evaluate <tt>init.rb</tt> if present 177 177 # 178 178 # After all plugins are loaded, duplicates are removed from the load path. 179 # Plugins are loaded in alphabetical order. 179 # If an array of plugin names is specified in config.plugins, the plugins 180 # will be loaded in that order. Otherwise, plugins are loaded in alphabetical 181 # order. 180 182 def load_plugins 181 find_plugins(configuration.plugin_paths).sort.each { |path| load_plugin path } 183 if configuration.plugins.nil? 184 # a nil value implies we don't care about plugins; load 'em all in a reliable order 185 find_plugins(configuration.plugin_paths).sort.each { |path| load_plugin path } 186 elsif !configuration.plugins.empty? 187 # we've specified a config.plugins array, so respect that order 188 plugin_paths = find_plugins(configuration.plugin_paths) 189 configuration.plugins.each do |name| 190 path = plugin_paths.find { |p| File.basename(p) == name } 191 load_plugin path 192 end 193 end 182 194 $LOAD_PATH.uniq! 183 195 end 184 196 … … 345 357 end 346 358 347 359 def plugin_enabled?(path) 348 configuration.plugins. empty? || configuration.plugins.include?(File.basename(path))360 configuration.plugins.nil? || configuration.plugins.include?(File.basename(path)) 349 361 end 350 362 351 363 # Load the plugin at <tt>path</tt> unless already loaded. … … 470 482 # any method of +nil+. Set to +false+ for the standard Ruby behavior. 471 483 attr_accessor :whiny_nils 472 484 473 # The list of plugins to load. If this is set to <tt>[]</tt>, all plugins will be loaded. 485 # The list of plugins to load. If this is set to <tt>nil</tt>, all plugins will 486 # be loaded. If this is set to <tt>[]</tt>, no plugins will be loaded. Otherwise, 487 # plugins will be loaded in the order specified. 474 488 attr_accessor :plugins 475 489 476 490 # The path to the root of the plugins directory. By default, it is in … … 642 656 end 643 657 644 658 def default_plugins 645 []659 nil 646 660 end 647 661 648 662 def default_plugin_paths