Files
grecia/app/lib/acts_as_paranoid_aliases.rb
Javi Martín cb477149c4 Move lib folder inside the app folder
The purpose of the lib folder is to have code that doesn't necessary
belong in the application but can be shared with other applications.

However, we don't have other applications and, if we did, the way to
share code between them would be using a gem or even a git submodule.

So having both the `app/` and the `lib/` folders is confusing IMHO, and
it causes unnecessary problems with autoloading.

So we're moving the `lib/` folder to `app/lib/`. Originally, some of
these files were in the `app/services/` folder and then they were moved
to the `lib/` folder. We're using `app/lib/` instead of `app/services/`
so the upgrade is less confusing.

There's an exception, though. The `OmniAuth::Strategies::Wordpress`
class needs to be available in the Devise initializer. Since this is an
initializer and trying to autoload a class here will be problematic when
switching to Zeitwerk, we'll keep the `require` clause on top of the
Devise initializer in order to load the file and so it will be loaded
even if it isn't in the autoload paths anymore.
2024-04-11 19:08:01 +02: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