debian-mirror-gitlab/app/models/concerns/ttl_expirable.rb

20 lines
490 B
Ruby
Raw Normal View History

2021-11-18 22:05:49 +05:30
# frozen_string_literal: true
module TtlExpirable
extend ActiveSupport::Concern
included do
validates :status, presence: true
2021-12-11 22:18:48 +05:30
default_value_for :read_at, Time.zone.now
2021-11-18 22:05:49 +05:30
2022-03-02 08:16:31 +05:30
enum status: { default: 0, pending_destruction: 1, processing: 2, error: 3 }
2021-11-18 22:05:49 +05:30
2021-12-11 22:18:48 +05:30
scope :read_before, ->(number_of_days) { where("read_at <= ?", Time.zone.now - number_of_days.days) }
2021-11-18 22:05:49 +05:30
scope :active, -> { where(status: :default) }
end
2021-12-11 22:18:48 +05:30
def read!
self.update(read_at: Time.zone.now)
end
2021-11-18 22:05:49 +05:30
end