aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/configuration.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails/configuration.rb')
-rw-r--r--railties/lib/rails/configuration.rb121
1 files changed, 79 insertions, 42 deletions
diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb
index 102a0836dc..f0a0d5e55e 100644
--- a/railties/lib/rails/configuration.rb
+++ b/railties/lib/rails/configuration.rb
@@ -1,27 +1,74 @@
require 'active_support/ordered_options'
module Rails
- class Configuration
- attr_accessor :cache_classes, :load_paths, :load_once_paths, :after_initialize_blocks,
- :frameworks, :framework_root_path, :root, :gems, :plugins,
- :i18n, :gems, :whiny_nils, :consider_all_requests_local,
- :action_controller, :active_record, :action_view, :active_support,
- :action_mailer, :active_resource,
- :reload_plugins, :log_path, :log_level, :logger, :preload_frameworks,
- :database_configuration_file, :cache_store, :time_zone,
- :view_path, :metals, :controller_paths, :routes_configuration_file,
- :eager_load_paths, :dependency_loading, :paths, :serve_static_assets
-
- def initialize
+ # Temporarily separate the plugin configuration class from the main
+ # configuration class while this bit is being cleaned up.
+ class Railtie::Configuration
+
+ def self.default
+ @default ||= new
+ end
+
+ attr_reader :middleware
+
+ def initialize(base = nil)
+ if base
+ @options = base.options.dup
+ @middleware = base.middleware.dup
+ else
+ @options = Hash.new { |h,k| h[k] = ActiveSupport::OrderedOptions.new }
+ @middleware = ActionDispatch::MiddlewareStack.new
+ end
+ end
+
+ def respond_to?(name)
+ super || name.to_s =~ config_key_regexp
+ end
+
+ protected
+
+ attr_reader :options
+
+ private
+
+ def method_missing(name, *args, &blk)
+ if name.to_s =~ config_key_regexp
+ return $2 == '=' ? @options[$1] = args.first : @options[$1]
+ end
+
+ super
+ end
+
+ def config_key_regexp
+ bits = config_keys.map { |n| Regexp.escape(n.to_s) }.join('|')
+ /^(#{bits})(?:=)?$/
+ end
+
+ def config_keys
+ ([ :active_support, :action_view ] +
+ Railtie.plugin_names).map { |n| n.to_s }.uniq
+ end
+ end
+
+ class Configuration < Railtie::Configuration
+ attr_accessor :after_initialize_blocks, :cache_classes,
+ :consider_all_requests_local, :dependency_loading, :gems,
+ :load_once_paths, :logger, :metals, :plugins,
+ :preload_frameworks, :reload_plugins, :serve_static_assets,
+ :time_zone, :whiny_nils
+
+ attr_writer :cache_store, :controller_paths,
+ :database_configuration_file, :eager_load_paths,
+ :i18n, :load_paths,
+ :log_level, :log_path, :paths, :routes_configuration_file,
+ :view_path
+
+ def initialize(base = nil)
+ super
@load_once_paths = []
@after_initialize_blocks = []
@dependency_loading = true
@serve_static_assets = true
-
- for framework in frameworks
- self.send("#{framework}=", ActiveSupport::OrderedOptions.new)
- end
- self.active_support = ActiveSupport::OrderedOptions.new
end
def after_initialize(&blk)
@@ -31,7 +78,7 @@ module Rails
def root
@root ||= begin
call_stack = caller.map { |p| p.split(':').first }
- root_path = call_stack.detect { |p| p !~ %r[railties/lib/rails] }
+ root_path = call_stack.detect { |p| p !~ %r[railties/lib/rails|rack/lib/rack] }
root_path = File.dirname(root_path)
while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/config.ru")
@@ -72,6 +119,13 @@ module Rails
end
end
+ def frameworks(*args)
+ raise "config.frameworks in no longer supported. See the generated" \
+ "config/boot.rb for steps on how to limit the frameworks that" \
+ "will be loaded"
+ end
+ alias frameworks= frameworks
+
# Enable threaded mode. Allows concurrent requests to controller actions and
# multiple database connections. Also disables automatic dependency loading
# after boot, and disables reloading code on every request, as these are
@@ -80,28 +134,11 @@ module Rails
self.preload_frameworks = true
self.cache_classes = true
self.dependency_loading = false
- self.action_controller.allow_concurrency = true
- self
- end
- def framework_paths
- paths = %w(railties railties/lib activesupport/lib)
- paths << 'actionpack/lib' if frameworks.include?(:action_controller) || frameworks.include?(:action_view)
-
- [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
- paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include?(framework)
+ if respond_to?(:action_controller)
+ action_controller.allow_concurrency = true
end
-
- paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
- end
-
- def framework_root_path
- defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root}/vendor/rails"
- end
-
- def middleware
- require 'action_dispatch'
- @middleware ||= ActionDispatch::MiddlewareStack.new
+ self
end
# Loads and returns the contents of the #database_configuration_file. The
@@ -116,6 +153,10 @@ module Rails
@routes_configuration_file ||= File.join(root, 'config', 'routes.rb')
end
+ def builtin_routes_configuration_file
+ @builtin_routes_configuration_file ||= File.join(RAILTIES_PATH, 'builtin', 'routes.rb')
+ end
+
def controller_paths
@controller_paths ||= begin
paths = [File.join(root, 'app', 'controllers')]
@@ -190,10 +231,6 @@ module Rails
@log_level ||= RAILS_ENV == 'production' ? :info : :debug
end
- def frameworks
- @frameworks ||= [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
- end
-
def i18n
@i18n ||= begin
i18n = ActiveSupport::OrderedOptions.new