2018-08-03 13:22:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-18 17:45:41 -04:00
|
|
|
module Expirable
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2019-12-10 02:53:40 -05:00
|
|
|
DAYS_TO_EXPIRE = 7
|
|
|
|
|
2016-08-18 17:45:41 -04:00
|
|
|
included do
|
|
|
|
scope :expired, -> { where('expires_at <= ?', Time.current) }
|
|
|
|
end
|
|
|
|
|
2016-10-06 11:19:27 -04:00
|
|
|
def expired?
|
|
|
|
expires? && expires_at <= Time.current
|
|
|
|
end
|
|
|
|
|
2016-08-18 17:45:41 -04:00
|
|
|
def expires?
|
|
|
|
expires_at.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def expires_soon?
|
2019-12-10 02:53:40 -05:00
|
|
|
expires? && expires_at < DAYS_TO_EXPIRE.days.from_now
|
2016-08-18 17:45:41 -04:00
|
|
|
end
|
|
|
|
end
|