Browse files

add missing "with/only destroyed" methods for consistency

  • Loading branch information...
1 parent 5ea623f commit 56d5e925cf57bd3acfe7b3c5406464517ab4a35d @chewi chewi committed with Apr 21, 2010
Showing with 21 additions and 0 deletions.
  1. +21 −0 lib/is_paranoid.rb
View
21 lib/is_paranoid.rb
@@ -34,6 +34,11 @@ def self.count_with_destroyed *args
self.with_destroyed_scope { count(*args) }
end
+ # Perform a count only on destroyed instances.
+ def self.count_only_destroyed *args
+ self.with_only_destroyed_scope { count(*args) }
+ end
+
# Return instances of all models matching the query regardless
# of whether or not they have been soft-deleted.
def self.find_with_destroyed *args
@@ -45,6 +50,17 @@ def self.find_only_destroyed *args
self.with_only_destroyed_scope { find(*args) }
end
+ # Returns true if the requested record exists, even if it has
+ # been soft-deleted.
+ def self.exists_with_destroyed? *args
+ self.with_destroyed_scope { exists?(*args) }
+ end
+
+ # Returns true if the requested record has been soft-deleted.
+ def self.exists_only_destroyed? *args
+ self.with_only_destroyed_scope { exists?(*args) }
+ end
+
# Override the default destroy to allow us to flag deleted_at.
# This preserves the before_destroy and after_destroy callbacks.
# Because this is also called internally by Model.destroy_all and
@@ -64,6 +80,11 @@ def restore
self.deleted_at = nil
update_without_callbacks
end
+
+ # Has this model been soft-deleted?
+ def destroyed?
+ super || !deleted_at.nil?
+ end
protected

0 comments on commit 56d5e92

Please sign in to comment.