Module: DirtyCallbacks

Defined in:
lib/dirty_callbacks.rb

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dirty_callbacks.rb', line 2

def self.included(klass)
  klass.class_eval do
    columns.each do |f|
      f = f.name
      define_callbacks :"before_#{f}_changes_on_update", :"after_#{f}_changed_on_update"

      before_update do |o|
        o.send :callback, :"before_#{f}_changes_on_update" if o.send :"#{f}_changed?"
      end

      after_update do |o|
        o.send :callback, :"after_#{f}_changed_on_update" if o.send :"#{f}_changed?"
      end
    end
  end
end