diff --git a/actionmailer/lib/action_mailer/rails.rb b/actionmailer/lib/action_mailer/rails.rb new file mode 100644 index 0000000000000000000000000000000000000000..a3573cdea7a1dcde492e35ac65111d528b40a688 --- /dev/null +++ b/actionmailer/lib/action_mailer/rails.rb @@ -0,0 +1,24 @@ +require "action_mailer" + +module ActionMailer + class Plugin < Rails::Plugin + plugin_name :action_mailer + + initializer "action_mailer.set_configs" do |app| + app.config.action_mailer.each do |k,v| + ActionMailer::Base.send "#{k}=", v + end + end + + # TODO: ActionController::Base.logger should delegate to its own config.logger + initializer "action_mailer.logger" do + ActionMailer::Base.logger ||= Rails.logger + end + + initializer "action_mailer.view_paths" do |app| + # TODO: this should be combined with the logic for default config.action_mailer.view_paths + view_path = ActionView::PathSet.type_cast(app.config.view_path, app.config.cache_classes) + ActionMailer::Base.template_root = view_path if ActionMailer::Base.view_paths.blank? + end + end +end \ No newline at end of file diff --git a/actionpack/lib/action_controller/notifications.rb b/actionpack/lib/action_controller/notifications.rb deleted file mode 100644 index 1a4f29e0e23eaf0ff0042871d3d83a7ecae5ee52..0000000000000000000000000000000000000000 --- a/actionpack/lib/action_controller/notifications.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'active_support/notifications' - -ActiveSupport::Notifications.subscribe(/(read|write|cache|expire|exist)_(fragment|page)\??/) do |*args| - event = ActiveSupport::Notifications::Event.new(*args) - - if logger = ActionController::Base.logger - human_name = event.name.to_s.humanize - logger.info("#{human_name} (%.1fms)" % event.duration) - end -end diff --git a/actionpack/lib/action_controller/rails.rb b/actionpack/lib/action_controller/rails.rb index c2d753f9ef384c90e07a82ddbd3adf55277fb130..36a52b3149fe6073aef33ca78affc1c810e8cfeb 100644 --- a/actionpack/lib/action_controller/rails.rb +++ b/actionpack/lib/action_controller/rails.rb @@ -23,5 +23,80 @@ class Plugin < Rails::Plugin app.route_configuration_files << app.config.builtin_routes_configuration_file app.reload_routes! end + + # Include middleware to serve up static assets + initializer "action_controller.initialize_static_server" do |app| + if app.config.serve_static_assets + app.config.middleware.use(ActionDispatch::Static, Rails.public_path) + end + end + + initializer "action_controller.initialize_middleware_stack" do |app| + middleware = app.config.middleware + middleware.use(::Rack::Lock, :if => lambda { ActionController::Base.allow_concurrency }) + middleware.use(::Rack::Runtime) + middleware.use(ActionDispatch::ShowExceptions, lambda { ActionController::Base.consider_all_requests_local }) + middleware.use(ActionDispatch::Callbacks, lambda { ActionController::Dispatcher.prepare_each_request }) + middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options }) + middleware.use(ActionDispatch::ParamsParser) + middleware.use(::Rack::MethodOverride) + middleware.use(::Rack::Head) + middleware.use(ActionDispatch::StringCoercion) + end + + initializer "action_controller.initialize_framework_caches" do + ActionController::Base.cache_store ||= RAILS_CACHE + end + + # Sets +ActionController::Base#view_paths+ and +ActionMailer::Base#template_root+ + # (but only for those frameworks that are to be loaded). If the framework's + # paths have already been set, it is not changed, otherwise it is + # set to use Configuration#view_path. + initializer "action_controller.initialize_framework_views" do |app| + # TODO: this should be combined with the logic for default config.action_controller.view_paths + view_path = ActionView::PathSet.type_cast(app.config.view_path, app.config.cache_classes) + ActionController::Base.view_paths = view_path if ActionController::Base.view_paths.blank? + end + + initializer "action_controller.initialize_metal" do |app| + Rails::Rack::Metal.requested_metals = app.config.metals + + app.config.middleware.insert_before(:"ActionDispatch::ParamsParser", + Rails::Rack::Metal, :if => Rails::Rack::Metal.metals.any?) + end + + # # Prepare dispatcher callbacks and run 'prepare' callbacks + initializer "action_controller.prepare_dispatcher" do |app| + # TODO: This used to say unless defined?(Dispatcher). Find out why and fix. + require 'rails/dispatcher' + + Dispatcher.define_dispatcher_callbacks(app.config.cache_classes) + + unless app.config.cache_classes + # Setup dev mode route reloading + routes_last_modified = app.routes_changed_at + reload_routes = lambda do + unless app.routes_changed_at == routes_last_modified + routes_last_modified = app.routes_changed_at + app.reload_routes! + end + end + ActionDispatch::Callbacks.before_dispatch { |callbacks| reload_routes.call } + end + end + + initializer "action_controller.notifications" do |app| + require 'active_support/notifications' + + ActiveSupport::Notifications.subscribe(/(read|write|cache|expire|exist)_(fragment|page)\??/) do |*args| + event = ActiveSupport::Notifications::Event.new(*args) + + if logger = ActionController::Base.logger + human_name = event.name.to_s.humanize + logger.info("#{human_name} (%.1fms)" % event.duration) + end + end + end + end end \ No newline at end of file diff --git a/activerecord/lib/active_record/notifications.rb b/activerecord/lib/active_record/notifications.rb deleted file mode 100644 index 562a5b91f455c283252d9f0da0885208e88656ca..0000000000000000000000000000000000000000 --- a/activerecord/lib/active_record/notifications.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'active_support/notifications' - -ActiveSupport::Notifications.subscribe("sql") do |name, before, after, result, instrumenter_id, payload| - ActiveRecord::Base.connection.log_info(payload[:sql], name, after - before) -end diff --git a/activerecord/lib/active_record/rails.rb b/activerecord/lib/active_record/rails.rb index 4071385563e2dc344459a5efe796c898fb3917fc..ddbc5551133ab7cb2e19672265a28bd6707c18b5 100644 --- a/activerecord/lib/active_record/rails.rb +++ b/activerecord/lib/active_record/rails.rb @@ -47,5 +47,13 @@ class Plugin < Rails::Plugin ActiveRecord::Base.logger ||= Rails.logger end + initializer "active_record.notifications" do + require 'active_support/notifications' + + ActiveSupport::Notifications.subscribe("sql") do |name, before, after, result, instrumenter_id, payload| + ActiveRecord::Base.connection.log_info(payload[:sql], name, after - before) + end + end + end end \ No newline at end of file diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 9a5656fb1deb4e50413100ab8310312edf1a523a..8ba24af793895b8aaee8d79e0a63fd3e2555a2bd 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -139,14 +139,6 @@ def call(env) $LOAD_PATH.uniq! end - # # Requires all frameworks specified by the Configuration#frameworks - # # list. By default, all frameworks (Active Record, Active Support, - # # Action Pack, Action Mailer, and Active Resource) are loaded. - # initializer :require_frameworks do - # require 'active_support/all' unless config.active_support.bare - # config.frameworks.each { |framework| require(framework.to_s) } - # end - # Set the paths from which Rails will automatically load source files, and # the load_once paths. initializer :set_autoload_paths do @@ -177,34 +169,7 @@ def call(env) # Used by Passenger to ensure everything's loaded before forking and # to avoid autoload race conditions in JRuby. initializer :preload_frameworks do - if config.preload_frameworks - config.frameworks.each do |framework| - # String#classify and #constantize aren't available yet. - toplevel = Object.const_get(framework.to_s.gsub(/(?:^|_)(.)/) { $1.upcase }) - toplevel.load_all! if toplevel.respond_to?(:load_all!) - end - end - end - - # Include middleware to serve up static assets - initializer :initialize_static_server do - if defined?(ActionController) && config.serve_static_assets - config.middleware.use(ActionDispatch::Static, Rails.public_path) - end - end - - initializer :initialize_middleware_stack do - if defined?(ActionController) - config.middleware.use(::Rack::Lock, :if => lambda { ActionController::Base.allow_concurrency }) - config.middleware.use(::Rack::Runtime) - config.middleware.use(ActionDispatch::ShowExceptions, lambda { ActionController::Base.consider_all_requests_local }) - config.middleware.use(ActionDispatch::Callbacks, lambda { ActionController::Dispatcher.prepare_each_request }) - config.middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options }) - config.middleware.use(ActionDispatch::ParamsParser) - config.middleware.use(::Rack::MethodOverride) - config.middleware.use(::Rack::Head) - config.middleware.use(ActionDispatch::StringCoercion) - end + ActiveSupport::Autoload.eager_load! if config.preload_frameworks end initializer :initialize_cache do @@ -218,12 +183,6 @@ def call(env) end end - initializer :initialize_framework_caches do - if defined?(ActionController) - ActionController::Base.cache_store ||= RAILS_CACHE - end - end - initializer :initialize_logger do # if the environment has explicitly defined a logger, use it next if Rails.logger @@ -254,14 +213,6 @@ def call(env) # logger is already set, it is not changed, otherwise it is set to use # RAILS_DEFAULT_LOGGER. initializer :initialize_framework_logging do - for framework in [ :action_controller, :action_mailer ] - # TODO BEFORE PUSHING: REMOVEZ - begin - framework.to_s.camelize.constantize.const_get("Base").logger ||= Rails.logger - rescue Exception - end - end - ActiveSupport::Dependencies.logger ||= Rails.logger Rails.cache.logger ||= Rails.logger end @@ -308,46 +259,6 @@ def call(env) end end - # Initializes framework-specific settings for each of the loaded frameworks - # (Configuration#frameworks). The available settings map to the accessors - # on each of the corresponding Base classes. - initializer :initialize_framework_settings do - (config.frameworks - [:active_record, :action_controller]).each do |framework| - # TODO BEFORE PUSHING: This needs to work differently - begin - base_class = framework.to_s.camelize.constantize.const_get("Base") - - config.send(framework).each do |setting, value| - base_class.send("#{setting}=", value) - end - rescue Exception - end - end - end - - # Sets +ActionController::Base#view_paths+ and +ActionMailer::Base#template_root+ - # (but only for those frameworks that are to be loaded). If the framework's - # paths have already been set, it is not changed, otherwise it is - # set to use Configuration#view_path. - initializer :initialize_framework_views do - if defined?(ActionView) - view_path = ActionView::PathSet.type_cast(config.view_path, config.cache_classes) - - ActionMailer::Base.template_root = view_path if defined?(ActionMailer) && ActionMailer::Base.view_paths.blank? - ActionController::Base.view_paths = view_path if defined?(ActionController) && ActionController::Base.view_paths.blank? - end - end - - initializer :initialize_metal do - if defined?(ActionController) - Rails::Rack::Metal.requested_metals = config.metals - - config.middleware.insert_before( - :"ActionDispatch::ParamsParser", - Rails::Rack::Metal, :if => Rails::Rack::Metal.metals.any?) - end - end - # # bail out if gems are missing - note that check_gem_dependencies will have # # already called abort() unless $gems_rake_task is set # return unless gems_dependencies_loaded @@ -364,27 +275,6 @@ def call(env) end end - # TODO: Make a DSL way to limit an initializer to a particular framework - - # # Prepare dispatcher callbacks and run 'prepare' callbacks - initializer :prepare_dispatcher do - next unless configuration.frameworks.include?(:action_controller) - require 'rails/dispatcher' unless defined?(::Dispatcher) - Dispatcher.define_dispatcher_callbacks(configuration.cache_classes) - - unless configuration.cache_classes - # Setup dev mode route reloading - routes_last_modified = routes_changed_at - reload_routes = lambda do - unless routes_changed_at == routes_last_modified - routes_last_modified = routes_changed_at - reload_routes! - end - end - ActionDispatch::Callbacks.before_dispatch { |callbacks| reload_routes.call } - end - end - # Eager load application classes initializer :load_application_classes do next if $rails_rake_task diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 49c548ad5c38f8cf24e02a859bd7bbec5337ebc9..725dd06929be31f6c2b564d82dd82443148a2527 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -171,6 +171,8 @@ def baz end RUBY + sleep 0.1 + get '/foo' assert_equal 'baz', last_response.body end