module Deleteable
Public Class Methods
included(receiver)
click to toggle source
# File lib/deleteable.rb, line 3 def self.included(receiver) receiver.extend ClassMethods receiver.class_eval do default_scope where("deleted_at IS NULL") end end
Public Instance Methods
delete()
click to toggle source
# File lib/deleteable.rb, line 22 def delete update_attribute(:deleted_at,Time.now) end
destroy(hard_delete=false)
click to toggle source
Calls superclass method
# File lib/deleteable.rb, line 14 def destroy(hard_delete=false) if !hard_delete && self.class.column_names.include?('deleted_at') delete else super end end
is_deleted?()
click to toggle source
# File lib/deleteable.rb, line 10 def is_deleted? !deleted_at.nil? end
undelete()
click to toggle source
# File lib/deleteable.rb, line 26 def undelete update_attribute(:deleted_at,nil) end