Created
January 19, 2011 08:36
-
-
Save vrybas/785875 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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