Changeset 7531
- Timestamp:
- 09/21/07 22:31:19 (1 year ago)
- Files:
-
- trunk/railties/CHANGELOG (modified) (1 diff)
- trunk/railties/environments/environment.rb (modified) (1 diff)
- trunk/railties/lib/initializer.rb (modified) (2 diffs)
- trunk/railties/lib/rails/plugin/loader.rb (modified) (3 diffs)
- trunk/railties/test/plugin_loader_test.rb (modified) (1 diff)
- trunk/railties/test/plugin_locator_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/railties/CHANGELOG
r7507 r7531 1 1 *SVN* 2 3 * Added the :all option to config.plugins that'll include the rest of the plugins not already explicitly named #9613 [fcheung]. Example: 4 5 # Loads :classic_pagination before all the other plugins 6 config.plugins = [ :classic_pagination, :all ] 7 8 * Removed deprecated task names, like clear_logs, in favor of the new namespaced style [DHH] 2 9 3 10 * Support multiple config.after_initialize blocks so plugins and apps can more easily cooperate. #9582 [zdennis] trunk/railties/environments/environment.rb
r7483 r7531 17 17 # config.frameworks -= [ :active_resource, :action_mailer ] 18 18 19 # Only load the plugins named here, by default all plugins in vendor/plugins are loaded 20 # config.plugins = %W( exception_notification ssl_requirement ) 19 # Only load the plugins named here, in the order given. By default all plugins in vendor/plugins are loaded, in alphabetical order 20 # :all can be used as a placeholder for all plugins not explicitly named. 21 # config.plugins = [ :exception_notification, :ssl_requirement, :all ] 21 22 22 23 # Add additional load paths for your own custom dirs trunk/railties/lib/initializer.rb
r7507 r7531 178 178 # and they plugins will be loaded in that order. Otherwise, plugins are loaded in alphabetical 179 179 # order. 180 # 181 # if config.plugins ends contains :all then the named plugins will be loaded in the given order and all other 182 # plugins will be loaded in alphabetical order 180 183 def load_plugins 181 184 configuration.plugin_locators.each do |locator| … … 340 343 def ensure_all_registered_plugins_are_loaded! 341 344 unless configuration.plugins.nil? 342 unless loaded_plugins == configuration.plugins343 missing_plugins = configuration.plugins - loaded_plugins345 if configuration.plugins.detect {|plugin| plugin != :all && !loaded_plugins.include?( plugin)} 346 missing_plugins = configuration.plugins - (loaded_plugins + [:all]) 344 347 raise LoadError, "Could not locate the following plugins: #{missing_plugins.to_sentence}" 345 348 end trunk/railties/lib/rails/plugin/loader.rb
r6293 r7531 37 37 !explicit_plugin_loading_order? || registered? 38 38 end 39 39 40 def explicitly_enabled? 41 !explicit_plugin_loading_order? || explicitly_registered? 42 end 43 40 44 def registered? 45 explicit_plugin_loading_order? && registered_plugins_names_plugin?(name) 46 end 47 48 def explicitly_registered? 41 49 explicit_plugin_loading_order? && registered_plugins.include?(name) 42 50 end … … 53 61 def registered_plugins 54 62 config.plugins 63 end 64 65 def registered_plugins_names_plugin?(plugin_name) 66 registered_plugins.include?(plugin_name) || registered_plugins.include?(:all) 55 67 end 56 68 … … 105 117 # Evaluate in init.rb 106 118 def evaluate 107 silence_warnings { eval(IO.read(init_path), binding, init_path) } if has_init_file?119 silence_warnings { eval(IO.read(init_path), binding, init_path) } if has_init_file? 108 120 end 109 121 110 122 def <=>(other_plugin_loader) 111 123 if explicit_plugin_loading_order? 112 if non_existent_plugin = [self, other_plugin_loader].detect { |plugin| !registered_plugins.include?(plugin.name)}124 if non_existent_plugin = [self, other_plugin_loader].detect { |plugin| !registered_plugins_names_plugin?(plugin.name) } 113 125 plugin_does_not_exist!(non_existent_plugin.name) 114 126 end 115 127 116 registered_plugins.index(name) <=> registered_plugins.index(other_plugin_loader.name) 128 if !explicitly_enabled? && !other_plugin_loader.explicitly_enabled? 129 name <=> other_plugin_loader.name 130 elsif registered_plugins.include?(:all) && (!explicitly_enabled? || !other_plugin_loader.explicitly_enabled?) 131 effective_index = explicitly_enabled? ? registered_plugins.index(name) : registered_plugins.index(:all) 132 other_effective_index = other_plugin_loader.explicitly_enabled? ? 133 registered_plugins.index(other_plugin_loader.name) : registered_plugins.index(:all) 134 135 effective_index <=> other_effective_index 136 else 137 registered_plugins.index(name) <=> registered_plugins.index(other_plugin_loader.name) 138 end 139 117 140 else 118 141 name <=> other_plugin_loader.name trunk/railties/test/plugin_loader_test.rb
r6290 r7531 13 13 only_load_the_following_plugins! %w(stubby acts_as_chunky_bacon) 14 14 assert loader.send(:explicit_plugin_loading_order?) 15 end 16 17 def test_enabled_if_not_named_explicitly 18 stubby_loader = loader_for(@valid_plugin_path) 19 acts_as_loader = loader_for('acts_as/acts_as_chunky_bacon') 20 21 only_load_the_following_plugins! ['stubby', :all] 22 assert stubby_loader.send(:enabled?) 23 assert acts_as_loader.send(:enabled?) 24 25 assert stubby_loader.send(:explicitly_enabled?) 26 assert !acts_as_loader.send(:explicitly_enabled?) 15 27 end 16 28 trunk/railties/test/plugin_locator_test.rb
r6292 r7531 27 27 end 28 28 29 def test_all_plugins_loaded_when_all_is_used 30 plugin_names = ['stubby', 'acts_as_chunky_bacon', :all] 31 only_load_the_following_plugins! plugin_names 32 failure_tip = "It's likely someone has added a new plugin fixture without updating this list" 33 assert_equal %w(stubby acts_as_chunky_bacon a plugin_with_no_lib_dir), @locator.plugin_names, failure_tip 34 end 35 36 def test_all_plugins_loaded_after_all 37 plugin_names = ['stubby', :all, 'acts_as_chunky_bacon'] 38 only_load_the_following_plugins! plugin_names 39 failure_tip = "It's likely someone has added a new plugin fixture without updating this list" 40 assert_equal %w(stubby a plugin_with_no_lib_dir acts_as_chunky_bacon ), @locator.plugin_names, failure_tip 41 end 42 29 43 30 44 def test_registering_a_plugin_name_that_does_not_exist_raises_a_load_error