Module: Expirable

Defined in:
lib/mega/expirable.rb

Overview

:title: Expirable

Generic expiring functionality mixin.

Usage

TODO: If anyone has an example of using this please submit. -T

Author(s)

  • George Moschovitis

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#expiresObject

Returns the value of attribute expires.



39
40
41
# File 'lib/mega/expirable.rb', line 39

def expires
  @expires
end

Instance Method Details

#expired?Boolean

Is this entry expired?

Returns:

  • (Boolean)


56
57
58
59
60
61
62
# File 'lib/mega/expirable.rb', line 56

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.



43
44
45
# File 'lib/mega/expirable.rb', line 43

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.



50
51
52
# File 'lib/mega/expirable.rb', line 50

def expires_spread(base, spread)
  @expires = Time.now + base + rand(spread)
end