class Goalkeeper::Goal
Goal
represents a label which has either been met
or not.
Attributes
expiration[R]
the TTL value for the Redis record. Defalts to Goalkeeper.expiration
label[R]
The unique label to identify this Goal
. There is no logic to check that the label is unique.
Public Class Methods
new(*label, expiration: Goalkeeper.expiration)
click to toggle source
label
is a unique string to identify this Goal
. If multiple args are passed they are joined and seperated by ':' expiration
number secconds. This can be set to override the gobal expiration.
# File lib/goalkeeper/goal.rb, line 14 def initialize(*label, expiration: Goalkeeper.expiration) @label = label.join(":") @expiration = expiration end
Public Instance Methods
==(other)
click to toggle source
All Goalkeeper::Goals with the same label are equal
# File lib/goalkeeper/goal.rb, line 51 def ==(other) other.is_a?(Goalkeeper::Goal) && other.label == label end
clear!()
click to toggle source
clear! removes the met state of the Goal
.
# File lib/goalkeeper/goal.rb, line 36 def clear! Goalkeeper.redis.del(key) end
key()
click to toggle source
a namespaced key for the goal
# File lib/goalkeeper/goal.rb, line 41 def key "#{Goalkeeper.namespace}:#{label}" end
met!()
click to toggle source
# File lib/goalkeeper/goal.rb, line 19 def met! write unless met? self end
met?()
click to toggle source
# File lib/goalkeeper/goal.rb, line 24 def met? !read.nil? end
met_at()
click to toggle source
Time the goal was completed. WARNING retuns nil if the job is not met
# File lib/goalkeeper/goal.rb, line 30 def met_at return Time.parse(read) if met? nil end
ttl()
click to toggle source
ttl returns the time to live on the redis key
# File lib/goalkeeper/goal.rb, line 46 def ttl Goalkeeper.redis.ttl(key) end
Protected Instance Methods
read()
click to toggle source
# File lib/goalkeeper/goal.rb, line 62 def read Goalkeeper.redis.get(key) end
write()
click to toggle source
# File lib/goalkeeper/goal.rb, line 57 def write Goalkeeper.redis.set(key, Time.now) Goalkeeper.redis.expire(key, expiration) end