Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #25 from leereilly/fix-instancemethods-deprecation…

…-warning

Remove InstanceMethods deprecation warning
  • Loading branch information...
commit 02421b482406e9e50c8a503622703e5978910560 2 parents a0978d5 + e5fbd73
@patmaddox authored
Showing with 24 additions and 26 deletions.
  1. +24 −26 lib/no_peeping_toms.rb
View
50 lib/no_peeping_toms.rb
@@ -45,38 +45,36 @@ def observer_enabled?(observer)
end
end
- module InstanceMethods
- # Overrides ActiveRecord#define_callbacks so that observers are only called
- # when enabled.
- #
- # This is a bit yuck being a protected method, but appears to be the cleanest
- # way so far
- def define_callbacks_with_enabled_check(klass)
- observer = self
- observer_name = observer.class.name.underscore.gsub('/', '__')
+ # Overrides ActiveRecord#define_callbacks so that observers are only called
+ # when enabled.
+ #
+ # This is a bit yuck being a protected method, but appears to be the cleanest
+ # way so far
+ def define_callbacks_with_enabled_check(klass)
+ observer = self
+ observer_name = observer.class.name.underscore.gsub('/', '__')
- ActiveRecord::Callbacks::CALLBACKS.each do |callback|
- next unless respond_to?(callback)
- callback_meth = :"_notify_#{observer_name}_for_#{callback}"
- unless klass.respond_to?(callback_meth)
- klass.send(:define_method, callback_meth) do
- observer.send(callback, self) if observer.observer_enabled?
- end
- klass.send(callback, callback_meth)
+ ActiveRecord::Callbacks::CALLBACKS.each do |callback|
+ next unless respond_to?(callback)
+ callback_meth = :"_notify_#{observer_name}_for_#{callback}"
+ unless klass.respond_to?(callback_meth)
+ klass.send(:define_method, callback_meth) do
+ observer.send(callback, self) if observer.observer_enabled?
end
+ klass.send(callback, callback_meth)
end
end
+ end
- # Enables interception of custom observer notifications, i.e.
- # notify_observers(:custom_notification)
- def update(*args, &block)
- super if observer_enabled?
- end
+ # Enables interception of custom observer notifications, i.e.
+ # notify_observers(:custom_notification)
+ def update(*args, &block)
+ super if observer_enabled?
+ end
- # Determines whether this observer should be run
- def observer_enabled?
- self.class.observer_enabled?(self)
- end
+ # Determines whether this observer should be run
+ def observer_enabled?
+ self.class.observer_enabled?(self)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.