Skip to content

Instantly share code, notes, and snippets.

@jamtur01
Created August 5, 2012 17:53
Show Gist options
  • Save jamtur01/3266286 to your computer and use it in GitHub Desktop.
Save jamtur01/3266286 to your computer and use it in GitHub Desktop.
Datamapper hook hackery
class Item
include DataMapper::Resource
belongs_to :user
has n, :comments, :constraint => :destroy
has_tags
property :id, Serial
property :status, Text
property :created_at, DateTime, :default => DateTime.now
property :updated_on, DateTime
validates_presence_of :status
before :save, :count
after :save do |item|
if @saved == 0
@saved = 1
Statum::SendEmail.new(item)
end
end
def count
if !self.saved?
@saved = 0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment