Class: Goalkeeper::Goal

Inherits:
Object
  • Object
show all
Defined in:
lib/goalkeeper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, ref: nil, expiration: Goalkeeper.expiration) ⇒ Goal

label is a unique string to identify this Goal. There is no checking if it is truly unique.

ref is an optional reference to any object. This would be used by the end user's application.

expiration can be set to override the gobal expiratin.


143
144
145
146
147
# File 'lib/goalkeeper.rb', line 143

def initialize(label, ref: nil, expiration: Goalkeeper.expiration)
  @label = label
  @ref = ref
  @expiration = expiration
end

Instance Attribute Details

#expirationObject (readonly)

the TTL value for the Redis record. Defalts to Goalkeeper.expiration


134
135
136
# File 'lib/goalkeeper.rb', line 134

def expiration
  @expiration
end

#labelObject (readonly)

The unique label to identify this Goal


127
128
129
# File 'lib/goalkeeper.rb', line 127

def label
  @label
end

#refObject (readonly)

An optional object refrence which allows an application author to associate this goal to an object. The ref is not used by Goalkeeper.


131
132
133
# File 'lib/goalkeeper.rb', line 131

def ref
  @ref
end

Instance Method Details

#keyObject

a namespaced key for the goal


169
170
171
# File 'lib/goalkeeper.rb', line 169

def key
  "#{Goalkeeper.namespace}:#{label}"
end

#met!Object


149
150
151
152
# File 'lib/goalkeeper.rb', line 149

def met!
  write
  self
end

#met?Boolean

Returns:

  • (Boolean)

154
155
156
# File 'lib/goalkeeper.rb', line 154

def met?
  ! read.nil?
end

#met_atObject

Time the goal was completed. WARNING retuns nil if the job is not met


160
161
162
163
164
165
166
# File 'lib/goalkeeper.rb', line 160

def met_at
  if met?
    Time.parse(read)
  else
    nil
  end
end