Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not depend on railties, only load railtie if Rails is defined
- Loading branch information
Rafael Mendonça França
committed
Dec 8, 2012
1 parent
0fa0863
commit ad733ef
Showing
4 changed files
with
37 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,2 @@ | ||
require 'rails' | ||
require 'rails/observers/version' | ||
|
||
module Rails | ||
module Observers | ||
class Railtie < ::Rails::Railtie | ||
initializer "active_record.observer", :before => "active_record.set_configs" do |app| | ||
ActiveSupport.on_load(:active_record) do | ||
require "rails/observers/activerecord/active_record" | ||
|
||
if observers = app.config.respond_to?(:active_record) && app.config.active_record.delete(:observers) | ||
send :observers=, observers | ||
end | ||
end | ||
end | ||
|
||
initializer "action_controller.caching.sweepers" do | ||
ActiveSupport.on_load(:action_controller) do | ||
require "rails/observers/action_controller/caching" | ||
end | ||
end | ||
|
||
config.after_initialize do |app| | ||
ActiveSupport.on_load(:active_record) do | ||
ActiveRecord::Base.instantiate_observers | ||
|
||
ActionDispatch::Reloader.to_prepare do | ||
ActiveRecord::Base.instantiate_observers | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
require 'rails/observers/railtie' if defined? Rails | ||
This comment has been minimized.
Sorry, something went wrong. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'rails/railtie' | ||
|
||
module Rails | ||
module Observers | ||
class Railtie < ::Rails::Railtie | ||
initializer "active_record.observer", :before => "active_record.set_configs" do |app| | ||
ActiveSupport.on_load(:active_record) do | ||
require "rails/observers/activerecord/active_record" | ||
|
||
if observers = app.config.respond_to?(:active_record) && app.config.active_record.delete(:observers) | ||
send :observers=, observers | ||
end | ||
end | ||
end | ||
|
||
initializer "action_controller.caching.sweepers" do | ||
ActiveSupport.on_load(:action_controller) do | ||
require "rails/observers/action_controller/caching" | ||
end | ||
end | ||
|
||
config.after_initialize do |app| | ||
ActiveSupport.on_load(:active_record) do | ||
ActiveRecord::Base.instantiate_observers | ||
|
||
ActionDispatch::Reloader.to_prepare do | ||
ActiveRecord::Base.instantiate_observers | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The previous require (rails/observers/version) defines the Rails module so this will always try to load the Railtie.