Skip to content

Commit

Permalink
Fix up AR extension by using Railties module instead of Rails and req…
Browse files Browse the repository at this point in the history
…uiring ControllerRuntime at initialization time instead of boot
  • Loading branch information
jeremy committed Dec 31, 2009
1 parent d349b22 commit 10a2638
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
1 change: 0 additions & 1 deletion activerecord/lib/active_record.rb
Expand Up @@ -60,7 +60,6 @@ module ActiveRecord
autoload :Batches autoload :Batches
autoload :Calculations autoload :Calculations
autoload :Callbacks autoload :Callbacks
autoload :ControllerRuntime
autoload :DynamicFinderMatch autoload :DynamicFinderMatch
autoload :DynamicScopeMatch autoload :DynamicScopeMatch
autoload :Migration autoload :Migration
Expand Down
15 changes: 9 additions & 6 deletions activerecord/lib/active_record/rails.rb
Expand Up @@ -3,17 +3,14 @@
# here. This is needed for correctly setting up the middleware. # here. This is needed for correctly setting up the middleware.
# In the future, this might become an optional require. # In the future, this might become an optional require.
require "action_controller/rails" require "action_controller/rails"
require "active_record/rails/controller_runtime"


module ActiveRecord module ActiveRecord
class Plugin < Rails::Plugin class Plugin < Rails::Plugin
plugin_name :active_record plugin_name :active_record
include_modules_in "ActiveRecord::Base" include_modules_in "ActiveRecord::Base"


config.action_controller.include "ActiveRecord::Rails::ControllerRuntime"

rake_tasks do rake_tasks do
load "active_record/rails/databases.rake" load "active_record/railties/databases.rake"
end end


initializer "active_record.set_configs" do |app| initializer "active_record.set_configs" do |app|
Expand All @@ -34,6 +31,12 @@ class Plugin < Rails::Plugin
ActiveRecord::Base.default_timezone = :utc ActiveRecord::Base.default_timezone = :utc
end end


# Expose database runtime to controller for logging.
initializer "active_record.log_runtime" do |app|
require "active_record/railties/controller_runtime"
ActionController::Base.send :include, ActiveRecord::Railties::ControllerRuntime
end

# Setup database middleware after initializers have run # Setup database middleware after initializers have run
initializer "active_record.initialize_database_middleware" do |app| initializer "active_record.initialize_database_middleware" do |app|
middleware = app.config.middleware middleware = app.config.middleware
Expand All @@ -52,7 +55,7 @@ class Plugin < Rails::Plugin


# TODO: ActiveRecord::Base.logger should delegate to its own config.logger # TODO: ActiveRecord::Base.logger should delegate to its own config.logger
initializer "active_record.logger" do initializer "active_record.logger" do
ActiveRecord::Base.logger ||= Rails.logger ActiveRecord::Base.logger ||= ::Rails.logger
end end


initializer "active_record.notifications" do initializer "active_record.notifications" do
Expand All @@ -64,4 +67,4 @@ class Plugin < Rails::Plugin
end end


end end
end end
@@ -1,7 +1,7 @@
require 'active_support/core_ext/module/attr_internal' require 'active_support/core_ext/module/attr_internal'


module ActiveRecord module ActiveRecord
module Rails module Railties
module ControllerRuntime module ControllerRuntime
extend ActiveSupport::Concern extend ActiveSupport::Concern


Expand Down

0 comments on commit 10a2638

Please sign in to comment.