Module: AfterCommit::ActiveSupportCallbacks

Defined in:
lib/after_commit/active_support_callbacks.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/after_commit/active_support_callbacks.rb', line 5

def self.included(base)
  
  base::Callback.class_eval do
    def have_callback?
      true
    end
  end
  
  base::CallbackChain.class_eval do
    def have_callback?
      any? &:have_callback?
    end
  end
  
  base.class_eval do
    def have_callback?(*callbacks)
      self.class.observers.size > 0 or
      self.class.count_observers > 0 or
      callbacks.any? do |callback|
        self.class.send("#{callback}_callback_chain").have_callback?
      end
    end
  end
  
end