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

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

30 lines
646 B
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
module Expirable
extend ActiveSupport::Concern
2020-01-01 13:55:28 +05:30
DAYS_TO_EXPIRE = 7
2016-09-13 17:45:13 +05:30
included do
2022-08-27 11:52:29 +05:30
scope :not, ->(scope) { where(scope.arel.constraints.reduce(:and).not) }
2023-06-20 00:43:36 +05:30
scope :expired, -> { where.not(expires_at: nil).where(arel_table[:expires_at].lteq(Time.current)) }
2022-08-27 11:52:29 +05:30
scope :not_expired, -> { self.not(expired) }
2016-09-13 17:45:13 +05:30
end
2017-08-17 22:00:37 +05:30
def expired?
expires? && expires_at <= Time.current
end
2021-10-27 15:23:28 +05:30
# Used in subclasses that override expired?
alias_method :expired_original?, :expired?
2016-09-13 17:45:13 +05:30
def expires?
expires_at.present?
end
def expires_soon?
2020-01-01 13:55:28 +05:30
expires? && expires_at < DAYS_TO_EXPIRE.days.from_now
2016-09-13 17:45:13 +05:30
end
end