aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-03-26 18:47:55 +0100
committerJosé Valim <jose.valim@gmail.com>2010-03-26 18:47:55 +0100
commit395d6648ce7549f71dd0a76dc061e87f608aaaab (patch)
tree4dbb6eb54ff784143bf6e2f671057f0b8162dba5
parentfc266d7ec2cf1d3f9daf585ea6b79b61467a175f (diff)
downloadrails-395d6648ce7549f71dd0a76dc061e87f608aaaab.tar.gz
rails-395d6648ce7549f71dd0a76dc061e87f608aaaab.tar.bz2
rails-395d6648ce7549f71dd0a76dc061e87f608aaaab.zip
Move application configuration to the application configuration object, remove railtie_name and engine_name and allow to set the configuration object.
-rw-r--r--actionmailer/lib/action_mailer/railtie.rb4
-rw-r--r--actionpack/lib/action_controller/base.rb1
-rw-r--r--actionpack/lib/action_controller/railtie.rb13
-rw-r--r--actionpack/lib/action_controller/railties/url_helpers.rb2
-rw-r--r--actionpack/lib/action_dispatch/railtie.rb3
-rw-r--r--actionpack/lib/action_view/base.rb4
-rw-r--r--actionpack/lib/action_view/railtie.rb12
-rw-r--r--activerecord/lib/active_record/railtie.rb5
-rw-r--r--activeresource/lib/active_resource/railtie.rb4
-rw-r--r--activesupport/lib/active_support/railtie.rb6
-rw-r--r--railties/lib/rails/application.rb2
-rw-r--r--railties/lib/rails/application/configuration.rb55
-rw-r--r--railties/lib/rails/engine.rb6
-rw-r--r--railties/lib/rails/railtie.rb22
-rw-r--r--railties/lib/rails/railtie/configuration.rb77
-rw-r--r--railties/lib/rails/test_unit/railtie.rb2
-rw-r--r--railties/test/railties/railtie_test.rb21
17 files changed, 109 insertions, 130 deletions
diff --git a/actionmailer/lib/action_mailer/railtie.rb b/actionmailer/lib/action_mailer/railtie.rb
index 0182e48425..2703367fdb 100644
--- a/actionmailer/lib/action_mailer/railtie.rb
+++ b/actionmailer/lib/action_mailer/railtie.rb
@@ -3,14 +3,14 @@ require "rails"
module ActionMailer
class Railtie < Rails::Railtie
- railtie_name :action_mailer
+ config.action_mailer = ActiveSupport::OrderedOptions.new
initializer "action_mailer.url_for", :before => :load_environment_config do |app|
ActionMailer.base_hook { include app.routes.url_helpers }
end
require "action_mailer/railties/log_subscriber"
- log_subscriber ActionMailer::Railties::LogSubscriber.new
+ log_subscriber :action_mailer, ActionMailer::Railties::LogSubscriber.new
initializer "action_mailer.logger" do
ActionMailer.base_hook { self.logger ||= Rails.logger }
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index ad2b68af21..5797282b41 100644
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -19,6 +19,7 @@ module ActionController
include SessionManagement
include ActionController::Caching
include ActionController::MimeResponds
+ include ActionController::PolymorphicRoutes
# Rails 2.x compatibility
include ActionController::Compatibility
diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb
index 2626a31fc2..0ec89928af 100644
--- a/actionpack/lib/action_controller/railtie.rb
+++ b/actionpack/lib/action_controller/railtie.rb
@@ -1,16 +1,17 @@
require "rails"
require "action_controller"
+require "action_dispatch/railtie"
require "action_view/railtie"
require "active_support/core_ext/class/subclasses"
require "active_support/deprecation/proxy_wrappers"
require "active_support/deprecation"
+require "action_controller/railties/log_subscriber"
+require "action_controller/railties/url_helpers"
+
module ActionController
class Railtie < Rails::Railtie
- railtie_name :action_controller
-
- require "action_controller/railties/log_subscriber"
- require "action_controller/railties/url_helpers"
+ config.action_controller = ActiveSupport::OrderedOptions.new
ad = config.action_dispatch
config.action_controller.singleton_class.send(:define_method, :session) do
@@ -37,7 +38,7 @@ module ActionController
ad.session_store = val
end
- log_subscriber ActionController::Railties::LogSubscriber.new
+ log_subscriber :action_controller, ActionController::Railties::LogSubscriber.new
initializer "action_controller.logger" do
ActionController.base_hook { self.logger ||= Rails.logger }
@@ -69,7 +70,7 @@ module ActionController
initializer "action_controller.url_helpers" do |app|
ActionController.base_hook do
- extend ::ActionController::Railtie::UrlHelpers.with(app.routes)
+ extend ::ActionController::Railties::UrlHelpers.with(app.routes)
end
message = "ActionController::Routing::Routes is deprecated. " \
diff --git a/actionpack/lib/action_controller/railties/url_helpers.rb b/actionpack/lib/action_controller/railties/url_helpers.rb
index ad2a8d4ef3..5f95e1c621 100644
--- a/actionpack/lib/action_controller/railties/url_helpers.rb
+++ b/actionpack/lib/action_controller/railties/url_helpers.rb
@@ -1,5 +1,5 @@
module ActionController
- class Railtie
+ module Railties
module UrlHelpers
def self.with(router)
Module.new do
diff --git a/actionpack/lib/action_dispatch/railtie.rb b/actionpack/lib/action_dispatch/railtie.rb
index e486bd4079..430c90e515 100644
--- a/actionpack/lib/action_dispatch/railtie.rb
+++ b/actionpack/lib/action_dispatch/railtie.rb
@@ -3,8 +3,7 @@ require "rails"
module ActionDispatch
class Railtie < Rails::Railtie
- railtie_name :action_dispatch
-
+ config.action_dispatch = ActiveSupport::OrderedOptions.new
config.action_dispatch.x_sendfile_header = "X-Sendfile"
config.action_dispatch.ip_spoofing_check = true
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 9eec8ecce8..919b1e3470 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -159,8 +159,6 @@ module ActionView #:nodoc:
include Helpers, Rendering, Partials, Layouts, ::ERB::Util, Context
extend ActiveSupport::Memoizable
- ActionView.run_base_hooks(self)
-
# Specify whether RJS responses should be wrapped in a try/catch block
# that alert()s the caught exception (and then re-raises it).
cattr_accessor :debug_rjs
@@ -175,6 +173,8 @@ module ActionView #:nodoc:
delegate :logger, :to => 'ActionController::Base', :allow_nil => true
end
+ ActionView.run_base_hooks(self)
+
attr_accessor :base_path, :assigns, :template_extension, :lookup_context
attr_internal :captures, :request, :controller, :template, :config
diff --git a/actionpack/lib/action_view/railtie.rb b/actionpack/lib/action_view/railtie.rb
index 2e5d115630..9cf007cd2b 100644
--- a/actionpack/lib/action_view/railtie.rb
+++ b/actionpack/lib/action_view/railtie.rb
@@ -3,10 +3,10 @@ require "rails"
module ActionView
class Railtie < Rails::Railtie
- railtie_name :action_view
+ config.action_view = ActiveSupport::OrderedOptions.new
require "action_view/railties/log_subscriber"
- log_subscriber ActionView::Railties::LogSubscriber.new
+ log_subscriber :action_view, ActionView::Railties::LogSubscriber.new
initializer "action_view.cache_asset_timestamps" do |app|
unless app.config.cache_classes
@@ -15,5 +15,13 @@ module ActionView
end
end
end
+
+ initializer "action_view.set_configs" do |app|
+ ActionView.base_hook do
+ app.config.action_view.each do |k,v|
+ send "#{k}=", v
+ end
+ end
+ end
end
end \ No newline at end of file
diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb
index 60addd46c6..de47461c73 100644
--- a/activerecord/lib/active_record/railtie.rb
+++ b/activerecord/lib/active_record/railtie.rb
@@ -10,7 +10,7 @@ require "action_controller/railtie"
module ActiveRecord
class Railtie < Rails::Railtie
- railtie_name :active_record
+ config.active_record = ActiveSupport::OrderedOptions.new
config.generators.orm :active_record, :migration => true,
:timestamps => true
@@ -19,9 +19,8 @@ module ActiveRecord
load "active_record/railties/databases.rake"
end
- # TODO If we require the wrong file, the error never comes up.
require "active_record/railties/log_subscriber"
- log_subscriber ActiveRecord::Railties::LogSubscriber.new
+ log_subscriber :active_record, ActiveRecord::Railties::LogSubscriber.new
initializer "active_record.initialize_timezone" do
ActiveRecord.base_hook do
diff --git a/activeresource/lib/active_resource/railtie.rb b/activeresource/lib/active_resource/railtie.rb
index 27c88415f6..aa878c7212 100644
--- a/activeresource/lib/active_resource/railtie.rb
+++ b/activeresource/lib/active_resource/railtie.rb
@@ -3,10 +3,10 @@ require "rails"
module ActiveResource
class Railtie < Rails::Railtie
- railtie_name :active_resource
+ config.active_resource = ActiveSupport::OrderedOptions.new
require "active_resource/railties/log_subscriber"
- log_subscriber ActiveResource::Railties::LogSubscriber.new
+ log_subscriber :active_resource, ActiveResource::Railties::LogSubscriber.new
initializer "active_resource.set_configs" do |app|
app.config.active_resource.each do |k,v|
diff --git a/activesupport/lib/active_support/railtie.rb b/activesupport/lib/active_support/railtie.rb
index d2c13e030d..e45d16ee96 100644
--- a/activesupport/lib/active_support/railtie.rb
+++ b/activesupport/lib/active_support/railtie.rb
@@ -3,7 +3,7 @@ require "rails"
module ActiveSupport
class Railtie < Rails::Railtie
- railtie_name :active_support
+ config.active_support = ActiveSupport::OrderedOptions.new
# Loads support for "whiny nil" (noisy warnings when methods are invoked
# on +nil+ values) if Configuration#whiny_nils is true.
@@ -30,9 +30,7 @@ end
module I18n
class Railtie < Rails::Railtie
- railtie_name :i18n
-
- # Initialize I18n load paths to an array
+ config.i18n = ActiveSupport::OrderedOptions.new
config.i18n.railties_load_path = []
config.i18n.load_path = []
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index 8b355dd76c..ec0bbbe6a8 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -44,6 +44,8 @@ module Rails
end
end
+ delegate :metal_loader, :to => :config
+
def require_environment!
environment = config.paths.config.environment.to_a.first
require environment if environment
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index 52f869b877..44635ff4f6 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -6,7 +6,7 @@ module Rails
include ::Rails::Configuration::Deprecated
attr_accessor :allow_concurrency, :cache_classes, :cache_store,
- :consider_all_requests_local, :dependency_loading,
+ :cookie_secret, :consider_all_requests_local, :dependency_loading,
:filter_parameters, :log_level, :logger, :metals,
:plugins, :preload_frameworks, :reload_engines, :reload_plugins,
:serve_static_assets, :time_zone, :whiny_nils
@@ -19,10 +19,16 @@ module Rails
@serve_static_assets = true
@time_zone = "UTC"
@consider_all_requests_local = true
+ @session_store = :cookie_store
+ @session_options = {}
end
def middleware
- @@default_middleware_stack ||= default_middleware
+ @middleware ||= default_middleware_stack
+ end
+
+ def metal_loader
+ @metal_loader ||= Rails::Application::MetalLoader.new
end
def paths
@@ -94,6 +100,51 @@ module Rails
Rails::LogSubscriber.colorize_logging = val
self.generators.colorize_logging = val
end
+
+ def session_store(*args)
+ if args.empty?
+ case @session_store
+ when :disabled
+ nil
+ when :active_record_store
+ ActiveRecord::SessionStore
+ when Symbol
+ ActionDispatch::Session.const_get(@session_store.to_s.camelize)
+ else
+ @session_store
+ end
+ else
+ @session_store = args.shift
+ @session_options = args.shift || {}
+ end
+ end
+
+ protected
+
+ def session_options
+ return @session_options unless @session_store == :cookie_store
+ @session_options.merge(:secret => @cookie_secret)
+ end
+
+ def default_middleware_stack
+ ActionDispatch::MiddlewareStack.new.tap do |middleware|
+ middleware.use('::ActionDispatch::Static', lambda { Rails.public_path }, :if => lambda { serve_static_assets })
+ middleware.use('::Rack::Lock', :if => lambda { !allow_concurrency })
+ middleware.use('::Rack::Runtime')
+ middleware.use('::Rails::Rack::Logger')
+ middleware.use('::ActionDispatch::ShowExceptions', lambda { consider_all_requests_local })
+ middleware.use("::ActionDispatch::RemoteIp", lambda { action_dispatch.ip_spoofing_check }, lambda { action_dispatch.trusted_proxies })
+ middleware.use('::Rack::Sendfile', lambda { action_dispatch.x_sendfile_header })
+ middleware.use('::ActionDispatch::Callbacks', lambda { !cache_classes })
+ middleware.use('::ActionDispatch::Cookies')
+ middleware.use(lambda { session_store }, lambda { session_options })
+ middleware.use('::ActionDispatch::Flash', :if => lambda { session_store })
+ middleware.use(lambda { metal_loader.build_middleware(metals) }, :if => lambda { metal_loader.metals.any? })
+ middleware.use('ActionDispatch::ParamsParser')
+ middleware.use('::Rack::MethodOverride')
+ middleware.use('::ActionDispatch::Head')
+ end
+ end
end
end
end
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index e4888cdef7..67a2dc6ac2 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -10,8 +10,8 @@ module Rails
class << self
attr_accessor :called_from
- alias :engine_name :railtie_name
- alias :engine_names :railtie_names
+ # TODO Remove this. It's deprecated.
+ alias :engine_name :railtie_name
def inherited(base)
unless base.abstract_railtie?
@@ -41,7 +41,7 @@ module Rails
end
end
- delegate :middleware, :paths, :metal_loader, :root, :to => :config
+ delegate :middleware, :paths, :root, :to => :config
def load_tasks
super
diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb
index f42985a904..f2c58ef4e0 100644
--- a/railties/lib/rails/railtie.rb
+++ b/railties/lib/rails/railtie.rb
@@ -10,7 +10,6 @@ module Rails
include Initializable
ABSTRACT_RAILTIES = %w(Rails::Railtie Rails::Plugin Rails::Engine Rails::Application)
- RAILTIES_TYPES = ABSTRACT_RAILTIES.map { |r| r.split('::').last }
class << self
def subclasses
@@ -24,17 +23,12 @@ module Rails
end
end
- def railtie_name(railtie_name = nil)
- @railtie_name = railtie_name if railtie_name
- @railtie_name ||= default_name
+ def railtie_name(*)
+ ActiveSupport::Deprecation.warn "railtie_name is deprecated and has no effect", caller
end
- def railtie_names
- subclasses.map { |p| p.railtie_name }
- end
-
- def log_subscriber(log_subscriber)
- Rails::LogSubscriber.add(railtie_name, log_subscriber)
+ def log_subscriber(name, log_subscriber)
+ Rails::LogSubscriber.add(name, log_subscriber)
end
def rake_tasks(&blk)
@@ -52,14 +46,6 @@ module Rails
def abstract_railtie?
ABSTRACT_RAILTIES.include?(name)
end
-
- protected
-
- def default_name
- namespaces = name.split("::")
- namespaces.pop if RAILTIES_TYPES.include?(namespaces.last)
- ActiveSupport::Inflector.underscore(namespaces.last).to_sym
- end
end
def rake_tasks
diff --git a/railties/lib/rails/railtie/configuration.rb b/railties/lib/rails/railtie/configuration.rb
index 828ccec3d0..16eccaccc4 100644
--- a/railties/lib/rails/railtie/configuration.rb
+++ b/railties/lib/rails/railtie/configuration.rb
@@ -3,11 +3,8 @@ require 'rails/configuration'
module Rails
class Railtie
class Configuration
- attr_accessor :cookie_secret
-
def initialize
- @session_store = :cookie_store
- @session_options = {}
+ @@options ||= {}
end
# Holds generators configuration:
@@ -48,76 +45,18 @@ module Rails
end
def respond_to?(name)
- super || name.to_s =~ config_key_regexp
- end
-
- def metal_loader
- @metal_loader ||= Rails::Application::MetalLoader.new
- end
-
- def session_store(*args)
- if args.empty?
- case @session_store
- when :disabled
- nil
- when :active_record_store
- ActiveRecord::SessionStore
- when Symbol
- ActionDispatch::Session.const_get(@session_store.to_s.camelize)
- else
- @session_store
- end
- else
- @session_store = args.shift
- @session_options = args.shift || {}
- end
+ super || @@options.key?(name.to_sym)
end
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 session_options
- return @session_options unless @session_store == :cookie_store
- @session_options.merge(:secret => @cookie_secret)
- end
-
- def config_key_regexp
- bits = config_keys.map { |n| Regexp.escape(n.to_s) }.join('|')
- /^(#{bits})(?:=)?$/
- end
-
- def config_keys
- (Railtie.railtie_names + Engine.engine_names).map { |n| n.to_s }.uniq
- end
-
- def options
- @@options ||= Hash.new { |h,k| h[k] = ActiveSupport::OrderedOptions.new }
- end
-
- def default_middleware
- require 'action_dispatch'
- ActionDispatch::MiddlewareStack.new.tap do |middleware|
- middleware.use('::ActionDispatch::Static', lambda { Rails.public_path }, :if => lambda { serve_static_assets })
- middleware.use('::Rack::Lock', :if => lambda { !allow_concurrency })
- middleware.use('::Rack::Runtime')
- middleware.use('::Rails::Rack::Logger')
- middleware.use('::ActionDispatch::ShowExceptions', lambda { consider_all_requests_local })
- middleware.use("::ActionDispatch::RemoteIp", lambda { action_dispatch.ip_spoofing_check }, lambda { action_dispatch.trusted_proxies })
- middleware.use('::Rack::Sendfile', lambda { action_dispatch.x_sendfile_header })
- middleware.use('::ActionDispatch::Callbacks', lambda { !cache_classes })
- middleware.use('::ActionDispatch::Cookies')
- middleware.use(lambda { session_store }, lambda { session_options })
- middleware.use('::ActionDispatch::Flash', :if => lambda { session_store })
- middleware.use(lambda { metal_loader.build_middleware(metals) }, :if => lambda { metal_loader.metals.any? })
- middleware.use('ActionDispatch::ParamsParser')
- middleware.use('::Rack::MethodOverride')
- middleware.use('::ActionDispatch::Head')
+ if name.to_s =~ /=$/
+ @@options[$`.to_sym] = args.first
+ elsif @@options.key?(name)
+ @@options[name]
+ else
+ super
end
end
end
diff --git a/railties/lib/rails/test_unit/railtie.rb b/railties/lib/rails/test_unit/railtie.rb
index d99325a6d8..e3fafc4b9d 100644
--- a/railties/lib/rails/test_unit/railtie.rb
+++ b/railties/lib/rails/test_unit/railtie.rb
@@ -1,7 +1,5 @@
module Rails
class TestUnitRailtie < Rails::Railtie
- railtie_name :test_unit
-
config.generators do |c|
c.test_framework :test_unit, :fixture => true,
:fixture_replacement => nil
diff --git a/railties/test/railties/railtie_test.rb b/railties/test/railties/railtie_test.rb
index 9fefb285b4..546bf5e143 100644
--- a/railties/test/railties/railtie_test.rb
+++ b/railties/test/railties/railtie_test.rb
@@ -32,28 +32,25 @@ module RailtiesTest
end
test "config name is available for the railtie" do
- class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end
+ class Foo < Rails::Railtie
+ config.foo = ActiveSupport::OrderedOptions.new
+ config.foo.greetings = "hello"
+ end
assert_equal "hello", Foo.config.foo.greetings
end
test "railtie configurations are available in the application" do
- class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end
+ class Foo < Rails::Railtie
+ config.foo = ActiveSupport::OrderedOptions.new
+ config.foo.greetings = "hello"
+ end
require "#{app_path}/config/application"
assert_equal "hello", AppTemplate::Application.config.foo.greetings
end
- test "railtie config merges are deep" do
- class Foo < Rails::Railtie ; config.foo.greetings = 'hello' ; end
- class Bar < Rails::Railtie
- config.foo.bar = "bar"
- end
- assert_equal "hello", Bar.config.foo.greetings
- assert_equal "bar", Bar.config.foo.bar
- end
-
test "railtie can add log subscribers" do
begin
- class Foo < Rails::Railtie ; log_subscriber(Rails::LogSubscriber.new) ; end
+ class Foo < Rails::Railtie ; log_subscriber(:foo, Rails::LogSubscriber.new) ; end
assert_kind_of Rails::LogSubscriber, Rails::LogSubscriber.log_subscribers[0]
ensure
Rails::LogSubscriber.log_subscribers.clear