Class: Goalkeeper::Goal
- Inherits:
-
Object
- Object
- Goalkeeper::Goal
- Defined in:
- lib/goalkeeper/goal.rb
Overview
Goal represents a label which has either been met
or not.
Instance Attribute Summary collapse
-
#expiration ⇒ Object
readonly
the TTL value for the Redis record.
-
#label ⇒ Object
readonly
The unique label to identify this Goal.
Instance Method Summary collapse
-
#==(other) ⇒ Object
All Goalkeeper::Goals with the same label are equal.
-
#clear! ⇒ Object
clear! removes the met state of the Goal.
-
#initialize(*label, expiration: Goalkeeper.expiration) ⇒ Goal
constructor
label
is a unique string to identify this Goal. -
#key ⇒ Object
a namespaced key for the goal.
- #met! ⇒ Object
- #met? ⇒ Boolean
-
#met_at ⇒ Object
Time the goal was completed.
-
#ttl ⇒ Object
ttl returns the time to live on the redis key.
Constructor Details
#initialize(*label, expiration: Goalkeeper.expiration) ⇒ Goal
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.
14 15 16 17 |
# File 'lib/goalkeeper/goal.rb', line 14 def initialize(*label, expiration: Goalkeeper.expiration) @label = label.join(":") @expiration = expiration end |
Instance Attribute Details
#expiration ⇒ Object (readonly)
the TTL value for the Redis record. Defalts to Goalkeeper.expiration
10 11 12 |
# File 'lib/goalkeeper/goal.rb', line 10 def expiration @expiration end |
#label ⇒ Object (readonly)
The unique label to identify this Goal. There is no logic to check that the label is unique.
7 8 9 |
# File 'lib/goalkeeper/goal.rb', line 7 def label @label end |
Instance Method Details
#==(other) ⇒ Object
All Goalkeeper::Goals with the same label are equal
51 52 53 |
# File 'lib/goalkeeper/goal.rb', line 51 def ==(other) other.is_a?(Goalkeeper::Goal) && other.label == label end |
#clear! ⇒ Object
clear! removes the met state of the Goal.
36 37 38 |
# File 'lib/goalkeeper/goal.rb', line 36 def clear! Goalkeeper.redis.del(key) end |
#key ⇒ Object
a namespaced key for the goal
41 42 43 |
# File 'lib/goalkeeper/goal.rb', line 41 def key "#{Goalkeeper.namespace}:#{label}" end |
#met! ⇒ Object
19 20 21 22 |
# File 'lib/goalkeeper/goal.rb', line 19 def met! write unless met? self end |
#met? ⇒ Boolean
24 25 26 |
# File 'lib/goalkeeper/goal.rb', line 24 def met? !read.nil? end |
#met_at ⇒ Object
Time the goal was completed. WARNING retuns nil if the job is not met
30 31 32 33 |
# File 'lib/goalkeeper/goal.rb', line 30 def met_at return Time.parse(read) if met? nil end |
#ttl ⇒ Object
ttl returns the time to live on the redis key
46 47 48 |
# File 'lib/goalkeeper/goal.rb', line 46 def ttl Goalkeeper.redis.ttl(key) end |