Files
grecia/lib/acts_as_paranoid_aliases.rb
dependabot[bot] 21d39bac62 Bump rubocop-rails from 2.20.2 to 2.21.2
Bumps [rubocop-rails](https://github.com/rubocop/rubocop-rails) from 2.20.2 to 2.21.2.
- [Release notes](https://github.com/rubocop/rubocop-rails/releases)
- [Changelog](https://github.com/rubocop/rubocop-rails/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop/rubocop-rails/compare/v2.20.2...v2.21.2)

---
updated-dependencies:
- dependency-name: rubocop-rails
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Note version 2.21.0 relaxes the default `Include` path for
`Rails/FindEach`, and so this version can find and correct offenses
outside the `app/models/` folder [1].

Also note this version replaces `unless something.include?` with `if
something.exclude?`; since we don't use the `exclude?` method anywhere,
we're removing the `include?` method from the list of methods checked by
this cop.

Finally, the Rails/HttpStatus method now returns a false positive when
rendering a dashboard partial and passing the `status` variable. In
order to avoid this issue, we could change the name of the local
variable or move the partial to a component, but for now we're simply
excluding these files for this cop.

[1] https://github.com/rubocop/rubocop-rails/pull/1059/commits/0066b3505

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-20 14:22:09 +01:00

70 lines
1.2 KiB
Ruby

module ActsAsParanoidAliases
def self.included(base)
base.extend(ClassMethods)
class_eval do
def hide
return false if hidden?
update_attribute(:hidden_at, Time.current)
after_hide
end
def hidden?
deleted?
end
def after_hide
end
def confirmed_hide?
confirmed_hide_at.present?
end
def confirm_hide
update_attribute(:confirmed_hide_at, Time.current)
end
def restore(opts = {})
return false unless hidden?
super(opts)
update_attribute(:confirmed_hide_at, nil) if self.class.column_names.include? "confirmed_hide_at"
after_restore
end
def after_restore
end
end
end
module ClassMethods
def with_confirmed_hide
where.not(confirmed_hide_at: nil)
end
def without_confirmed_hide
where(confirmed_hide_at: nil)
end
def with_hidden
with_deleted
end
def only_hidden
only_deleted
end
def hide_all(ids)
return if ids.blank?
where(id: ids).each(&:hide)
end
def restore_all(ids)
return if ids.blank?
only_hidden.where(id: ids).find_each(&:restore)
end
end
end