-
-
Save gramos/3209487 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 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