Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Remove InstanceMethods deprecation warning

Removes the following:

DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in NoPeepingToms instead. (called from include at /Volumes/GitHub/no-peeping-toms/spec/../lib/no_peeping_toms.rb:83)
  • Loading branch information...
commit e5fbd73ea182151d06b5a3d2919f99ce3ce5b592 1 parent a0978d5
Lee Reilly authored June 07, 2012

Showing 1 changed file with 24 additions and 26 deletions. Show diff stats Hide diff stats

  1. 50  lib/no_peeping_toms.rb
50  lib/no_peeping_toms.rb
@@ -45,38 +45,36 @@ def observer_enabled?(observer)
45 45
     end
46 46
   end
47 47
 
48  
-  module InstanceMethods
49  
-    # Overrides ActiveRecord#define_callbacks so that observers are only called
50  
-    # when enabled.
51  
-    #
52  
-    # This is a bit yuck being a protected method, but appears to be the cleanest
53  
-    # way so far
54  
-    def define_callbacks_with_enabled_check(klass)
55  
-      observer = self
56  
-      observer_name = observer.class.name.underscore.gsub('/', '__')
  48
+  # Overrides ActiveRecord#define_callbacks so that observers are only called
  49
+  # when enabled.
  50
+  #
  51
+  # This is a bit yuck being a protected method, but appears to be the cleanest
  52
+  # way so far
  53
+  def define_callbacks_with_enabled_check(klass)
  54
+    observer = self
  55
+    observer_name = observer.class.name.underscore.gsub('/', '__')
57 56
 
58  
-      ActiveRecord::Callbacks::CALLBACKS.each do |callback|
59  
-        next unless respond_to?(callback)
60  
-        callback_meth = :"_notify_#{observer_name}_for_#{callback}"
61  
-        unless klass.respond_to?(callback_meth)
62  
-          klass.send(:define_method, callback_meth) do
63  
-            observer.send(callback, self) if observer.observer_enabled?
64  
-          end
65  
-          klass.send(callback, callback_meth)
  57
+    ActiveRecord::Callbacks::CALLBACKS.each do |callback|
  58
+      next unless respond_to?(callback)
  59
+      callback_meth = :"_notify_#{observer_name}_for_#{callback}"
  60
+      unless klass.respond_to?(callback_meth)
  61
+        klass.send(:define_method, callback_meth) do
  62
+          observer.send(callback, self) if observer.observer_enabled?
66 63
         end
  64
+        klass.send(callback, callback_meth)
67 65
       end
68 66
     end
  67
+  end
69 68
 
70  
-    # Enables interception of custom observer notifications, i.e.
71  
-    #   notify_observers(:custom_notification)
72  
-    def update(*args, &block)
73  
-      super if observer_enabled?
74  
-    end
  69
+  # Enables interception of custom observer notifications, i.e.
  70
+  #   notify_observers(:custom_notification)
  71
+  def update(*args, &block)
  72
+    super if observer_enabled?
  73
+  end
75 74
 
76  
-    # Determines whether this observer should be run
77  
-    def observer_enabled?
78  
-      self.class.observer_enabled?(self)
79  
-    end
  75
+  # Determines whether this observer should be run
  76
+  def observer_enabled?
  77
+    self.class.observer_enabled?(self)
80 78
   end
81 79
 end
82 80
 

0 notes on commit e5fbd73

Please sign in to comment.
Something went wrong with that request. Please try again.