Module: Ohm::Callbacks

Defined in:
lib/ohm/callbacks.rb

Overview

The following is an example usage of this plugin:

class Post < Ohm::Model
  include Ohm::Callbacks

protected
  def before_create    # sanitize the decimal values here

  end

  def before_save    # do something here

  end

  def after_create    # do twitter posting here

  end

  def after_save    # do something with the ids

  end
end

Instance Method Summary collapse

Instance Method Details

#deleteObject


41
42
43
44
45
46
47
# File 'lib/ohm/callbacks.rb', line 41

def delete
  before_delete
  result = super
  after_delete

  return result
end

#saveObject


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ohm/callbacks.rb', line 25

def save
  is_new = new?

  before_create if is_new
  before_update if not is_new
  before_save

  result = super

  after_create if is_new
  after_update if not is_new
  after_save

  return result
end