Sha256: d28f575d37e5fa05ab222e8936406a4579d942b0b87363dd705de2b1a4e0054a

Contents?: true

Size: 995 Bytes

Versions: 11

Compression:

Stored size: 995 Bytes

Contents

# encoding: UTF-8

require File.expand_path("../helper", __FILE__)

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

  attribute :body

  def validate
    super

    assert_present :body
  end

  def did?(action)
    instance_variable_get("@#{ action }")
  end

  def count(action)
    instance_variable_get("@#{ action }")
  end

protected
  def before_create()   incr(:do_before_create)   end
  def after_create()    incr(:do_after_create)    end
  def before_save()     incr(:do_before_save)     end
  def after_save()      incr(:do_after_save)      end
  def before_update()   incr(:do_before_update)   end
  def after_update()    incr(:do_after_update)    end
  def before_delete()   incr(:do_before_delete)   end
  def after_delete()    incr(:do_after_delete)    end

  def incr(action)
    val = instance_variable_get("@#{ action }")
    val ||= 0
    val += 1

    instance_variable_set("@#{ action }", val)
  end
end

load File.expand_path('lint/callbacks.rb', File.dirname(__FILE__))

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ohm-contrib-2.0.0.alpha5 test/instance_callbacks.rb
ohm-contrib-2.0.0.alpha4 test/instance_callbacks.rb
ohm-contrib-2.0.0.alpha3 test/instance_callbacks.rb
ohm-contrib-2.0.0.alpha2 test/instance_callbacks.rb
ohm-contrib-1.2 test/instance_callbacks.rb
ohm-contrib-1.1.0 test/instance_callbacks.rb
ohm-contrib-1.0.1 test/instance_callbacks.rb
ohm-contrib-1.0.0 test/instance_callbacks.rb
ohm-contrib-1.0.0.rc5 test/instance_callbacks.rb
ohm-contrib-1.0.0.rc4 test/instance_callbacks.rb
ohm-contrib-1.0.0.rc3 test/instance_callbacks.rb