Browse files

Add one railtie to load the proper files depending of the frameworks

  • Loading branch information...
1 parent 0544c78 commit c4f9e102886896abae65493b2720453d366555e4 Rafael Mendonça França committed Oct 14, 2012
View
29 lib/rails-observers.rb
@@ -1,4 +1,29 @@
require "rails/observers/version"
-require "rails/observers/activerecord/observer"
-require "rails/observers/action_controller/caching"
+module Rails
+ module Observes
+ module Railtie < Rails::Railtie
+ initializer "active_record.observer" do
+ ActiveSupport.on_load(:active_record) do
+ require "rails/observers/activerecord/active_record"
+ end
+ end
+
+ initializer "action_controller.caching.sweppers" 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::Model.instantiate_observers
+
+ ActionDispatch::Reloader.to_prepare do
+ ActiveRecord::Model.instantiate_observers
+ end
+ end
+ end
+ end
+ end
+end
View
4 lib/rails/observers/activerecord/active_record.rb
@@ -1,3 +1,5 @@
+require 'rails/observers/activerecord/model'
+
module ActiveRecord
- autoload :Observer
+ autoload :Observer, 'rails/observers/activerecord/observer'
end
View
10 lib/rails/observers/activerecord/model.rb
@@ -1,9 +1,15 @@
+require 'rails/observers/active_model/active_model'
+
module ActiveRecord
module Model
- extend ActiveModel::Observing::ClassMethods
-
included do
+ extend ActiveModel::Observing::ClassMethods
include ActiveModel::Observing
end
end
+
+ class Base
+ extend ActiveModel::Observing::ClassMethods
+ include ActiveModel::Observing
+ end
end
View
2 lib/rails/observers/activerecord/observer.rb
@@ -1,5 +1,3 @@
-require 'rails/observers/active_model/active_model'
-
module ActiveRecord
# = Active Record Observer
#
View
13 lib/rails/observers/activerecord/railtie.rb
@@ -1,13 +0,0 @@
-module ActiveRecord
- class Railtie
- config.after_initialize do |app|
- ActiveSupport.on_load(:active_record) do
- ActiveRecord::Model.instantiate_observers
-
- ActionDispatch::Reloader.to_prepare do
- ActiveRecord::Model.instantiate_observers
- end
- end
- end
- end
-end
View
2 test/observer_array_test.rb
@@ -1,6 +1,6 @@
require 'minitest/autorun'
require 'active_model'
-require 'rails-observers'
+require 'rails/observers/active_model/active_model'
require 'models/observers'
class ObserverArrayTest < ActiveModel::TestCase
View
2 test/observing_test.rb
@@ -1,6 +1,6 @@
require 'minitest/autorun'
require 'active_model'
-require 'rails-observers'
+require 'rails/observers/active_model/active_model'
class ObservedModel
include ActiveModel::Observing
View
4 test/sweeper_test.rb
@@ -1,6 +1,8 @@
require 'minitest/autorun'
require 'action_controller'
-require 'rails-observers'
+require 'active_record'
+require 'rails/observers/activerecord/active_record'
+require 'rails/observers/action_controller/caching'
SharedTestRoutes = ActionDispatch::Routing::RouteSet.new

0 comments on commit c4f9e10

Please sign in to comment.