Skip to content

Commit

Permalink
Merge pull request #109 from DisruptionCorporation/observers-railtie-…
Browse files Browse the repository at this point in the history
…and-load-hooks

Instantiate observers via Railtie, and run load hooks
  • Loading branch information
guilleiguaran committed Jan 29, 2014
2 parents 16fe0c9 + dc15b1c commit c4eb476
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/active_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ module ActiveResource
autoload :Validations
autoload :Collection
end

require 'active_resource/railtie' if defined? Rails

3 changes: 3 additions & 0 deletions lib/active_resource/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1560,4 +1560,7 @@ class Base
include ActiveModel::Serializers::Xml
include ActiveResource::Reflection
end

ActiveSupport.run_load_hooks(:active_resource, Base)
end

13 changes: 12 additions & 1 deletion lib/active_resource/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,16 @@ class Railtie < Rails::Railtie
ActiveResource::Base.send "#{k}=", v
end
end

config.after_initialize do |app|
ActiveSupport.on_load(:active_resource) do
ActiveResource::Base.instantiate_observers

ActionDispatch::Reloader.to_prepare do
ActiveResource::Base.instantiate_observers
end
end
end
end
end
end

0 comments on commit c4eb476

Please sign in to comment.