diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2020-10-12 16:33:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-12 16:33:49 +0200 |
commit | 5e1364c448222c964faa469b6b5bfe9adf701c1a (patch) | |
tree | bf13de38f07f6a8ec4bdce9c6242c3c472bfddea /app/models/concerns | |
parent | dc52a778e111a67a5275dd4afecf3991e279e005 (diff) |
Add IP-based rules (#14963)
Diffstat (limited to 'app/models/concerns')
-rw-r--r-- | app/models/concerns/expireable.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/app/models/concerns/expireable.rb b/app/models/concerns/expireable.rb index f7d2bab49..a66a4661b 100644 --- a/app/models/concerns/expireable.rb +++ b/app/models/concerns/expireable.rb @@ -6,7 +6,15 @@ module Expireable included do scope :expired, -> { where.not(expires_at: nil).where('expires_at < ?', Time.now.utc) } - attr_reader :expires_in + def expires_in + return @expires_in if defined?(@expires_in) + + if expires_at.nil? + nil + else + (expires_at - created_at).to_i + end + end def expires_in=(interval) self.expires_at = interval.to_i.seconds.from_now if interval.present? |