Module: N::Expirable
- Included in:
- App::Fragment
- Defined in:
- lib/n/mixins.rb
Overview
Expirable
Generic expiring functionality mixin. This is not exclusive for entities.
Instance Attribute Summary collapse
-
#expires ⇒ Object
Returns the value of attribute expires.
Instance Method Summary collapse
-
#expired? ⇒ Boolean
Is this entry expired?.
-
#expires_after(timeout = (60*60*24)) ⇒ Object
Set the expires timeout for this entry.
-
#expires_spread(base, spread) ⇒ Object
Set the expire timeout for this entry.
Instance Attribute Details
#expires ⇒ Object
Returns the value of attribute expires.
20 21 22 |
# File 'lib/n/mixins.rb', line 20 def expires @expires end |
Instance Method Details
#expired? ⇒ Boolean
Is this entry expired?
37 38 39 40 41 42 43 |
# File 'lib/n/mixins.rb', line 37 def expired? if @expires.nil? or (Time.now > @expires) return true else return false end end |
#expires_after(timeout = (60*60*24)) ⇒ Object
Set the expires timeout for this entry.
24 25 26 |
# File 'lib/n/mixins.rb', line 24 def expires_after(timeout = (60*60*24)) @expires = Time.now + timeout end |
#expires_spread(base, spread) ⇒ Object
Set the expire timeout for this entry. The timeout happens after (base + rand(spread)) seconds.
31 32 33 |
# File 'lib/n/mixins.rb', line 31 def expires_spread(base, spread) @expires = Time.now + base + rand(spread) end |