Skip to content

Commit

Permalink
πŸ“ Add Yard documentation for Paranoia::Query (#555)
Browse files Browse the repository at this point in the history
  • Loading branch information
cprodhomme committed Mar 21, 2024
1 parent f68cb23 commit 0f8a3bd
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/paranoia.rb
Expand Up @@ -24,13 +24,15 @@ def self.included(klazz)
module Query
def paranoid? ; true ; end

# If you want to find all records, even those which are deleted
def with_deleted
if ActiveRecord::VERSION::STRING >= "4.1"
return unscope where: paranoia_column
end
all.tap { |x| x.default_scoped = false }
end

# If you want to find only the deleted records
def only_deleted
if paranoia_sentinel_value.nil?
return with_deleted.where.not(paranoia_column => paranoia_sentinel_value)
Expand All @@ -45,6 +47,7 @@ def only_deleted
end
alias_method :deleted, :only_deleted

# If you want to restore a record
def restore(id_or_ids, opts = {})
ids = Array(id_or_ids).flatten
any_object_instead_of_id = ids.any? { |id| ActiveRecord::Base === id }
Expand Down

0 comments on commit 0f8a3bd

Please sign in to comment.