Skip to content

Instantly share code, notes, and snippets.

@vrybas
Created January 19, 2011 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrybas/785875 to your computer and use it in GitHub Desktop.
Save vrybas/785875 to your computer and use it in GitHub Desktop.
module Deletable
def self.included(base)
base.class_eval do
named_scope :are, :conditions => ['`deleted_at` IS NULL']
named_scope :deleted, :conditions => ['`deleted_at` IS NOT NULL']
named_scope :deleted_at, lambda {|timestamp| {:conditions => ['`deleted_at` = ?',timestamp.to_formatted_s(:db)]}}
def self.foo
end
end
end
def mark_as_deleted(timestamp = Time.now.utc)
update_attribute(:deleted_at, timestamp)
end
def restore
update_attribute(:deleted_at, nil)
end
def deleted?
!!deleted_at
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment