This repository has been archived on 2024-06-09. You can view files and clone it, but cannot push or open issues/pull-requests.
2018-06-29 15:34:36 +02: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 19:22:46 +02:00
|
|
|
self.expires_at = interval.to_i.seconds.from_now if interval.present?
|
2018-06-29 15:34:36 +02:00
|
|
|
@expires_in = interval
|
|
|
|
end
|
|
|
|
|
|
|
|
def expire!
|
|
|
|
touch(:expires_at)
|
|
|
|
end
|
|
|
|
|
|
|
|
def expired?
|
2019-03-12 22:58:59 +01:00
|
|
|
expires? && expires_at < Time.now.utc
|
|
|
|
end
|
|
|
|
|
|
|
|
def expires?
|
|
|
|
!expires_at.nil?
|
2018-06-29 15:34:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|