diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-10-17 20:27:03 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-10-17 20:27:03 +0000 |
commit | c1a52510ea1d20990b047e8b2aa8a7154a931f1b (patch) | |
tree | a3310071e09c0b9c8830c8e1756ddb6cd40c3d72 | |
parent | 911f3db00abb7b35b400973c032e4e5c340bce6f (diff) | |
download | rails-c1a52510ea1d20990b047e8b2aa8a7154a931f1b.tar.gz rails-c1a52510ea1d20990b047e8b2aa8a7154a931f1b.tar.bz2 rails-c1a52510ea1d20990b047e8b2aa8a7154a931f1b.zip |
Added config.plugins to control which plugins are loaded #6269 [skaes]. By default, everything in vendor/plugins will be loaded, but if you specify config.plugins, only those will be loaded.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5317 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | railties/CHANGELOG | 4 | ||||
-rw-r--r-- | railties/environments/environment.rb | 7 | ||||
-rw-r--r-- | railties/lib/initializer.rb | 16 |
3 files changed, 23 insertions, 4 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 65c6a59974..eb18007d30 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,9 @@ *SVN* +* Added config.plugins to control which plugins are loaded #6269 [skaes]. By default, everything in vendor/plugins will be loaded, but if you specify config.plugins, only those will be loaded. Example: + + config.plugins = %w[ routing_navigator simply_helpful ] + * Clean up html on included error pages. [Tim Lucas] * Fixed default 404.html and 500.htmls to remove extreme ugliness and include human language [DHH] diff --git a/railties/environments/environment.rb b/railties/environments/environment.rb index ae63a4aa39..0bc8fda299 100644 --- a/railties/environments/environment.rb +++ b/railties/environments/environment.rb @@ -11,12 +11,15 @@ require File.join(File.dirname(__FILE__), 'boot') Rails::Initializer.run do |config| - # Settings in config/environments/* take precedence those specified here + # Settings in config/environments/* take precedence over those specified here # Skip frameworks you're not going to use (only works if using vendor/rails) # config.frameworks -= [ :action_web_service, :action_mailer ] - # Add additional load paths for your own custom dirs + # Only load the plugins named here, by default all plugins in vendor/plugins are loaded + # config.plugins = %W( exception_notification ssl_requirement ) + + # Add additional load paths (these paths will be subject to auto-loading of constants) # config.load_paths += %W( #{RAILS_ROOT}/extras ) # Force all environments to use the same logger level diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 0275026f41..1400930768 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -322,7 +322,7 @@ module Rails base_paths.flatten.inject([]) do |plugins, base_path| Dir.glob(File.join(base_path, '*')).each do |path| if plugin_path?(path) - plugins << path + plugins << path if plugin_enabled?(path) elsif File.directory?(path) plugins += find_plugins(path) end @@ -335,6 +335,10 @@ module Rails File.directory?(path) and (File.directory?(File.join(path, 'lib')) or File.file?(File.join(path, 'init.rb'))) end + def plugin_enabled?(path) + configuration.plugins.empty? || configuration.plugins.include?(File.basename(path)) + end + # Load the plugin at <tt>path</tt> unless already loaded. # # Each plugin is initialized: @@ -456,6 +460,9 @@ module Rails # Set to +true+ if you want to be warned (noisily) when you try to invoke # any method of +nil+. Set to +false+ for the standard Ruby behavior. attr_accessor :whiny_nils + + # The list of plugins to load. If this is set to <tt>[]</tt>, all plugins will be loaded. + attr_accessor :plugins # The path to the root of the plugins directory. By default, it is in # <tt>vendor/plugins</tt>. @@ -474,6 +481,7 @@ module Rails self.cache_classes = default_cache_classes self.breakpoint_server = default_breakpoint_server self.whiny_nils = default_whiny_nils + self.plugins = default_plugins self.plugin_paths = default_plugin_paths self.database_configuration_file = default_database_configuration_file @@ -624,6 +632,10 @@ module Rails false end + def default_plugins + [] + end + def default_plugin_paths ["#{root_path}/vendor/plugins"] end @@ -663,4 +675,4 @@ class Rails::OrderedOptions < Array #:nodoc: self.each { |i| return i if i.first == key } return false end -end
\ No newline at end of file +end |