Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📝 Add Yard documentation for Paranoia::Query #555

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/paranoia.rb
Original file line number Diff line number Diff line change
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