Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move application configuration to the application configuration objec…

…t, remove railtie_name and engine_name and allow to set the configuration object.
  • Loading branch information...
commit 395d6648ce7549f71dd0a76dc061e87f608aaaab 1 parent fc266d7
@josevalim josevalim authored
View
4 actionmailer/lib/action_mailer/railtie.rb
@@ -3,14 +3,14 @@
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 }
View
1  actionpack/lib/action_controller/base.rb
@@ -19,6 +19,7 @@ class Base < Metal
include SessionManagement
include ActionController::Caching
include ActionController::MimeResponds
+ include ActionController::PolymorphicRoutes
# Rails 2.x compatibility
include ActionController::Compatibility
View
13 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 @@ class Railtie < Rails::Railtie
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 @@ class Railtie < Rails::Railtie
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. " \
View
2  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
View
3  actionpack/lib/action_dispatch/railtie.rb
@@ -3,8 +3,7 @@
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
View
4 actionpack/lib/action_view/base.rb
@@ -159,8 +159,6 @@ module Subclasses
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 @@ class << self
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
View
12 actionpack/lib/action_view/railtie.rb
@@ -3,10 +3,10 @@
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 @@ class Railtie < Rails::Railtie
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
View
5 activerecord/lib/active_record/railtie.rb
@@ -10,7 +10,7 @@
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 @@ class Railtie < Rails::Railtie
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
View
4 activeresource/lib/active_resource/railtie.rb
@@ -3,10 +3,10 @@
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|
View
6 activesupport/lib/active_support/railtie.rb
@@ -3,7 +3,7 @@
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 @@ class Railtie < Rails::Railtie
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 = []
View
2  railties/lib/rails/application.rb
@@ -44,6 +44,8 @@ def method_missing(*args, &block)
end
end
+ delegate :metal_loader, :to => :config
+
def require_environment!
environment = config.paths.config.environment.to_a.first
require environment if environment
View
55 railties/lib/rails/application/configuration.rb
@@ -6,7 +6,7 @@ class Configuration < ::Rails::Engine::Configuration
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 @@ def initialize(*)
@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 @@ def colorize_logging=(val)
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
View
6 railties/lib/rails/engine.rb
@@ -10,8 +10,8 @@ class Engine < Railtie
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 @@ def find_root_with_flag(flag, default=nil)
end
end
- delegate :middleware, :paths, :metal_loader, :root, :to => :config
+ delegate :middleware, :paths, :root, :to => :config
def load_tasks
super
View
22 railties/lib/rails/railtie.rb
@@ -10,7 +10,6 @@ class Railtie
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 @@ def inherited(base)
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 @@ def generators(&blk)
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
View
77 railties/lib/rails/railtie/configuration.rb
@@ -3,11 +3,8 @@
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 @@ def to_prepare(&blk)
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
View
2  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
View
21 railties/test/railties/railtie_test.rb
@@ -32,28 +32,25 @@ class Foo < Rails::Railtie ; end
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
Please sign in to comment.
Something went wrong with that request. Please try again.