This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2018-06-29 06:34:36 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Expireable
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
scope :expired, -> { where.not(expires_at: nil).where('expires_at < ?', Time.now.utc) }
|
|
|
|
|
|
|
|
attr_reader :expires_in
|
|
|
|
|
|
|
|
def expires_in=(interval)
|
2018-08-26 10:22:46 -07:00
|
|
|
self.expires_at = interval.to_i.seconds.from_now if interval.present?
|
2018-06-29 06:34:36 -07:00
|
|
|
@expires_in = interval
|
|
|
|
end
|
|
|
|
|
|
|
|
def expire!
|
|
|
|
touch(:expires_at)
|
|
|
|
end
|
|
|
|
|
|
|
|
def expired?
|
2019-03-12 14:58:59 -07:00
|
|
|
expires? && expires_at < Time.now.utc
|
|
|
|
end
|
|
|
|
|
|
|
|
def expires?
|
|
|
|
!expires_at.nil?
|
2018-06-29 06:34:36 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|