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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

20 lines
498 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
2023-01-13 00:05:48 +05:30
attribute :read_at, default: -> { Time.zone.now }
2021-11-18 22:05:49 +05:30
validates :status, presence: true
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