Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 7531

Show
Ignore:
Timestamp:
09/21/07 22:31:19 (1 year ago)
Author:
david
Message:

Added the :all option to config.plugins thatll include the rest of the plugins not already explicitly named (closes #9613) [fcheung]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/railties/CHANGELOG

    r7507 r7531  
    11*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] 
    29 
    310* Support multiple config.after_initialize blocks so plugins and apps can more easily cooperate.  #9582 [zdennis] 
  • trunk/railties/environments/environment.rb

    r7483 r7531  
    1717  # config.frameworks -= [ :active_resource, :action_mailer ] 
    1818 
    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 ] 
    2122 
    2223  # Add additional load paths for your own custom dirs 
  • trunk/railties/lib/initializer.rb

    r7507 r7531  
    178178    # and they plugins will be loaded in that order. Otherwise, plugins are loaded in alphabetical 
    179179    # 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 
    180183    def load_plugins 
    181184      configuration.plugin_locators.each do |locator| 
     
    340343      def ensure_all_registered_plugins_are_loaded! 
    341344        unless configuration.plugins.nil? 
    342           unless loaded_plugins == configuration.plugins 
    343             missing_plugins = configuration.plugins - loaded_plugins 
     345          if configuration.plugins.detect {|plugin| plugin != :all && !loaded_plugins.include?( plugin)} 
     346            missing_plugins = configuration.plugins - (loaded_plugins + [:all]) 
    344347            raise LoadError, "Could not locate the following plugins: #{missing_plugins.to_sentence}" 
    345348          end 
  • trunk/railties/lib/rails/plugin/loader.rb

    r6293 r7531  
    3737        !explicit_plugin_loading_order? || registered? 
    3838      end 
    39          
     39       
     40      def explicitly_enabled? 
     41        !explicit_plugin_loading_order? || explicitly_registered? 
     42      end 
     43       
    4044      def registered? 
     45        explicit_plugin_loading_order? && registered_plugins_names_plugin?(name) 
     46      end 
     47 
     48      def explicitly_registered? 
    4149        explicit_plugin_loading_order? && registered_plugins.include?(name) 
    4250      end 
     
    5361        def registered_plugins 
    5462          config.plugins 
     63        end 
     64         
     65        def registered_plugins_names_plugin?(plugin_name) 
     66          registered_plugins.include?(plugin_name) || registered_plugins.include?(:all) 
    5567        end 
    5668         
     
    105117        # Evaluate in init.rb 
    106118        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? 
    108120        end 
    109121       
    110122        def <=>(other_plugin_loader) 
    111123          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)
    113125              plugin_does_not_exist!(non_existent_plugin.name) 
    114126            end 
    115127             
    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             
    117140          else 
    118141            name <=> other_plugin_loader.name 
  • trunk/railties/test/plugin_loader_test.rb

    r6290 r7531  
    1313    only_load_the_following_plugins! %w(stubby acts_as_chunky_bacon) 
    1414    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?) 
    1527  end 
    1628   
  • trunk/railties/test/plugin_locator_test.rb

    r6292 r7531  
    2727  end 
    2828   
     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   
    2943   
    3044  def test_registering_a_plugin_name_that_does_not_exist_raises_a_load_error