From c1a52510ea1d20990b047e8b2aa8a7154a931f1b Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 17 Oct 2006 20:27:03 +0000 Subject: [PATCH] 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 --- railties/CHANGELOG | 4 ++++ railties/environments/environment.rb | 7 +++++-- 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 @@ def find_plugins(*base_paths) 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 @@ def plugin_path?(path) 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 path unless already loaded. # # Each plugin is initialized: @@ -456,6 +460,9 @@ class Configuration # 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 [], all plugins will be loaded. + attr_accessor :plugins # The path to the root of the plugins directory. By default, it is in # vendor/plugins. @@ -474,6 +481,7 @@ def initialize 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 @@ def default_whiny_nils false end + def default_plugins + [] + end + def default_plugin_paths ["#{root_path}/vendor/plugins"] end @@ -663,4 +675,4 @@ def find_pair(key) self.each { |i| return i if i.first == key } return false end -end \ No newline at end of file +end -- GitLab