Module: N::Expirable
- Defined in:
- lib/glue/mixins.rb
Overview
Generic expiring functionality mixin.
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.
10 11 12 |
# File 'lib/glue/mixins.rb', line 10 def expires @expires end |
Instance Method Details
#expired? ⇒ Boolean
Is this entry expired?
27 28 29 30 31 32 33 |
# File 'lib/glue/mixins.rb', line 27 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.
14 15 16 |
# File 'lib/glue/mixins.rb', line 14 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.
21 22 23 |
# File 'lib/glue/mixins.rb', line 21 def expires_spread(base, spread) @expires = Time.now + base + rand(spread) end |