Skip to content

Instantly share code, notes, and snippets.

@Porta
Created April 20, 2011 18:31
Show Gist options
  • Save Porta/932239 to your computer and use it in GitHub Desktop.
Save Porta/932239 to your computer and use it in GitHub Desktop.
class Event < Ohm::Model
reference :user, lambda { |id| User.find(id)}
reference :item, lambda { |id| Item.find(id)}
reference :transaction, lambda { |id|Transaction.find(id)}
attribute :kind
attribute :text
attribute :created_at
index :user_id
index :item_id
index :transaction_id
index :created_at
KINDS = %w[registration creation reception delivery]
def validate
assert_present :kind
#KINDS = %w[registration creation reception delivery]
assert KINDS.include?(self.kind), [:kind, :not_valid]
#cheap before_create hook
self.created_at = Time.now
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment