class RedisFile::ExpiringHash
Represents a normal hash with some additional expiration information associated with each key
Attributes
expires[R]
Public Class Methods
new(*)
click to toggle source
Calls superclass method
# File lib/redis-file/expiring_hash.rb, line 7 def initialize(*) super @expires = {} end
Public Instance Methods
[](key)
click to toggle source
Calls superclass method
# File lib/redis-file/expiring_hash.rb, line 12 def [](key) key = normalize key delete(key) if expired?(key) super end
[]=(key, val)
click to toggle source
Calls superclass method
# File lib/redis-file/expiring_hash.rb, line 18 def []=(key, val) key = normalize key expire(key) super end
delete(key)
click to toggle source
Calls superclass method
# File lib/redis-file/expiring_hash.rb, line 24 def delete(key) key = normalize key expire(key) super end
expire(key)
click to toggle source
# File lib/redis-file/expiring_hash.rb, line 30 def expire(key) key = normalize key expires.delete(key) end
expired?(key)
click to toggle source
# File lib/redis-file/expiring_hash.rb, line 35 def expired?(key) key = normalize key expires.include?(key) && expires[key] < Time.now end
key?(key)
click to toggle source
Calls superclass method
# File lib/redis-file/expiring_hash.rb, line 40 def key?(key) key = normalize key delete(key) if expired?(key) super end
keys()
click to toggle source
Calls superclass method
# File lib/redis-file/expiring_hash.rb, line 54 def keys super.select do |key| key = normalize(key) if expired?(key) delete(key) false else true end end end
normalize(key)
click to toggle source
# File lib/redis-file/expiring_hash.rb, line 66 def normalize key key.to_s end
values_at(*keys)
click to toggle source
Calls superclass method
# File lib/redis-file/expiring_hash.rb, line 46 def values_at(*keys) keys.each do |key| key = normalize(key) delete(key) if expired?(key) end super end