Module: RiakRecord::Callbacks

Included in:
Base
Defined in:
lib/riak_record/callbacks.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

CALLBACK_TRIGGERS =
[
  :before_create, :after_create,
  :before_save, :after_save,
  :before_update, :after_update
]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



60
61
62
# File 'lib/riak_record/callbacks.rb', line 60

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#call_callbacks!(trigger) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/riak_record/callbacks.rb', line 10

def call_callbacks!(trigger)
  callbacks = self.class._callbacks(trigger)
  callbacks.each do |callback|
    if callback.is_a? Symbol
      self.send(callback)
    elsif callback.is_a? Proc
      callback.call(self)
    elsif callback.is_a? String
      eval(callback)
    else
      callback.send(trigger, self)
    end
  end
end