diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/application.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 55 | ||||
-rw-r--r-- | railties/lib/rails/engine.rb | 6 | ||||
-rw-r--r-- | railties/lib/rails/railtie.rb | 22 | ||||
-rw-r--r-- | railties/lib/rails/railtie/configuration.rb | 77 | ||||
-rw-r--r-- | railties/lib/rails/test_unit/railtie.rb | 2 | ||||
-rw-r--r-- | railties/test/railties/railtie_test.rb | 21 |
7 files changed, 79 insertions, 106 deletions
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 |