module NoBrainerSoftDelete
Constants
- VERSION
Public Instance Methods
deleted?()
click to toggle source
Returns a boolean indicating whether or not a document has been soft deleted
# File lib/no_brainer_soft_delete.rb, line 34 def deleted? !!deleted_at end
destroy()
click to toggle source
Sets the deleted_at value to the current time, thus marking the document as deleted
# File lib/no_brainer_soft_delete.rb, line 39 def destroy update(deleted_at: Time.now.utc) end
only_deleted()
click to toggle source
Returns only documents that have been soft deleted
# File lib/no_brainer_soft_delete.rb, line 23 def only_deleted unscoped.where(:deleted_at.defined => true) end
really_destroy!()
click to toggle source
Completely removes the document from the database, and runs the callbacks.
# File lib/no_brainer_soft_delete.rb, line 44 def really_destroy! _run_destroy_callbacks delete end
restore(id, options = {})
click to toggle source
Searches for a document and restores it
# File lib/no_brainer_soft_delete.rb, line 28 def restore(id, options = {}) with_deleted.where(id: id).first.restore(options) end
with_deleted()
click to toggle source
Returns documents regardless of the value held in deleted_at
# File lib/no_brainer_soft_delete.rb, line 18 def with_deleted unscoped.where(:or => [{ :deleted_at.defined => true }, { :deleted_at.undefined => true }]) end