Files
old-holivud2/app/models/concerns/archivable.rb
2020-05-31 22:38:19 +02:00

41 lines
1019 B
Ruby

module Archivable
extend ActiveSupport::Concern
included do
scope :active, -> { where("updated_at > ?", Config.active_threshold_date) }
scope :inactive, -> { where(updated_at: Config.inactive_date_range) }
scope :archived, -> { where("updated_at < ?", Config.archive_threshold_date) }
def archive_status
if updated_at > Config.active_threshold_date
:active
elsif updated_at.between? Config.archive_threshold_date, Config.active_threshold_date
:inactive
else
:archived
end
end
private
class Config
ACTIVE_THRESHOLD_IN_DAYS = 90
ARCHIVE_THRESHOLD_IN_DAYS = 365
class << self
def active_threshold_date
ACTIVE_THRESHOLD_IN_DAYS.days.ago.beginning_of_day
end
def archive_threshold_date
ARCHIVE_THRESHOLD_IN_DAYS.days.ago.end_of_day
end
def inactive_date_range
archive_threshold_date..active_threshold_date
end
end
end
end
end