Skip to content

Commit

Permalink
Added config.plugins to control which plugins are loaded #6269 [skaes…
Browse files Browse the repository at this point in the history
…]. 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
  • Loading branch information
dhh committed Oct 17, 2006
1 parent 911f3db commit c1a5251
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions railties/CHANGELOG
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
7 changes: 5 additions & 2 deletions railties/environments/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions railties/lib/initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <tt>path</tt> unless already loaded.
#
# Each plugin is initialized:
Expand Down Expand Up @@ -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 <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>.
Expand All @@ -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

Expand Down Expand Up @@ -624,6 +632,10 @@ def default_whiny_nils
false
end

def default_plugins
[]
end

def default_plugin_paths
["#{root_path}/vendor/plugins"]
end
Expand Down Expand Up @@ -663,4 +675,4 @@ def find_pair(key)
self.each { |i| return i if i.first == key }
return false
end
end
end

0 comments on commit c1a5251

Please sign in to comment.