Skip to content

Instantly share code, notes, and snippets.

@gramos
Forked from miloops/example.rb
Created July 30, 2012 19:39
Show Gist options
  • Save gramos/3209487 to your computer and use it in GitHub Desktop.
Save gramos/3209487 to your computer and use it in GitHub Desktop.
module ParanoidDeletion
def self.included(klass)
klass.send :include, InstanceMethods
klass.send :extend, ClassMethods
klass.send :default_scope, klass.where(deleted_at: nil)
end
module InstanceMethods
def destroy_without_callbacks
self.deleted_at = Time.now.utc
update_without_callbacks
end
def destroy
run_callbacks :destroy do
destroy_without_callbacks
end
end
def deleted?
!deleted_at.nil?
end
end
module ClassMethods
def find_with_deleted *args
self.with_exclusive_scope { find(*args) }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment