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

Changeset 5738

Show
Ignore:
Timestamp:
12/18/06 20:27:05 (3 years ago)
Author:
nzkoz
Message:

Reapply plugin load path changes from [5720]

Closes #6842
Closes #6851

Files:

Legend:

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

    r5722 r5738  
    11*SVN* 
     2 
     3* 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] 
    24 
    35* Don't generate a components directory in new Rails apps.  [Jeremy Kemper] 
  • trunk/railties/lib/initializer.rb

    r5722 r5738  
    4949    def initialize(configuration) 
    5050      @configuration = configuration 
    51       @loaded_plugins = Set.new 
     51      @loaded_plugins = [] 
    5252    end 
    5353 
     
    177177    # 
    178178    # 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. 
    180182    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          raise(LoadError, "Cannot find the plugin '#{name}'!") if path.nil? 
     192          load_plugin path 
     193        end 
     194      end  
    182195      $LOAD_PATH.uniq! 
    183196    end 
     
    346359 
    347360      def plugin_enabled?(path) 
    348         configuration.plugins.empty? || configuration.plugins.include?(File.basename(path)) 
     361        configuration.plugins.nil? || configuration.plugins.include?(File.basename(path)) 
    349362      end 
    350363 
     
    375388          application_lib_index = $LOAD_PATH.index(File.join(RAILS_ROOT, "lib")) || 0 
    376389          $LOAD_PATH.insert(application_lib_index + 1, lib_path) 
     390          Dependencies.load_paths << lib_path 
    377391        end 
    378392 
     
    471485    attr_accessor :whiny_nils 
    472486 
    473     # The list of plugins to load. If this is set to <tt>[]</tt>, all plugins will be loaded. 
     487    # The list of plugins to load. If this is set to <tt>nil</tt>, all plugins will 
     488    # be loaded. If this is set to <tt>[]</tt>, no plugins will be loaded. Otherwise, 
     489    # plugins will be loaded in the order specified. 
    474490    attr_accessor :plugins 
    475491 
     
    593609        ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) } 
    594610 
    595         paths.concat Dir["#{root_path}/vendor/plugins/*/lib/"] 
    596611        paths.concat builtin_directories 
    597612      end 
     
    643658 
    644659      def default_plugins 
    645         [] 
     660        nil 
    646661      end 
    647662 
  • trunk/railties/test/plugin_test.rb

    r5722 r5738  
    4444  def test_load_plugin 
    4545    stubby = "#{File.dirname(__FILE__)}/fixtures/plugins/default/stubby" 
    46     expected = Set.new(['stubby']) 
     46    expected = ['stubby'] 
    4747 
    4848    assert @init.send(:load_plugin, stubby) 
     
    6767    assert_loaded_plugins %w(a stubby acts_as_chunky_bacon), ['default', 'alternate'] 
    6868  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 
    6974 
     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 
     92  def test_raise_error_when_plugin_not_found 
     93    @init.configuration.plugins = %w(this_plugin_does_not_exist) 
     94    assert_raise(LoadError) { load_plugins(['default', 'alternate']) } 
     95  end 
     96   
    7097  protected 
    71     def assert_loaded_plugins(plugins, path) 
    72       assert_equal Set.new(plugins), load_plugins(path) 
     98    def assert_loaded_plugins(plugins, paths) 
     99      assert_equal plugins.sort, load_plugins(paths).sort 
     100    end 
     101     
     102    def assert_plugin_load_order(plugins, paths) 
     103      assert_equal plugins, load_plugins(paths) 
    73104    end 
    74105