Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/after_commit/active_support_callbacks.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.define_callbacks(*names) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/after_commit/active_support_callbacks.rb', line 38

def self.define_callbacks(*names)
  names.each do |name|
    instance_eval <<-RUBY
      def #{name}(*callbacks, &block)
        callbacks << block if block_given?
        write_inheritable_array(:#{name}, callbacks)
      end
    RUBY
  end
end

Instance Method Details

#have_callback?(*names) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
# File 'lib/after_commit/active_support_callbacks.rb', line 49

def have_callback?(*names)
  self.class.observers.size > 0 or
  self.class.count_observers > 0 or
  names.any? do |name|
    !self.class.read_inheritable_attribute(name).blank?
  end
end