Class: Fog::Rackspace::Queues::Mock::MockMessage
- Inherits:
-
Object
- Object
- Fog::Rackspace::Queues::Mock::MockMessage
- Defined in:
- lib/fog/rackspace/queues.rb
Overview
A single message posted to an in-memory MockQueue.
Instance Attribute Summary collapse
-
#claim ⇒ Object
Returns the value of attribute claim.
-
#created ⇒ Object
Returns the value of attribute created.
-
#data ⇒ Object
Returns the value of attribute data.
-
#id ⇒ Object
Returns the value of attribute id.
-
#producer_id ⇒ Object
Returns the value of attribute producer_id.
-
#queue ⇒ Object
Returns the value of attribute queue.
-
#ttl ⇒ Object
Returns the value of attribute ttl.
Instance Method Summary collapse
-
#age ⇒ Integer
Determine how long ago this message was created, in seconds.
-
#claimed? ⇒ Boolean
Return true if this message has been claimed.
-
#expired? ⇒ Boolean
Determine if this message has lived longer than its designated ttl.
-
#extend_life ⇒ Object
Extend the #ttl of this message to include the lifetime of the claim it belongs to, plus the claim’s grace period.
-
#href ⇒ String
Generate a URI segment that identifies this message.
-
#initialize(id, queue, client_id, data, ttl) ⇒ MockMessage
constructor
Create a new message.
-
#to_h ⇒ Hash
Convert this message to a GET payload.
Constructor Details
#initialize(id, queue, client_id, data, ttl) ⇒ MockMessage
Create a new message. Use Fog::Rackspace::Queues::Mock::MockQueue#add_message instead.
199 200 201 202 203 204 |
# File 'lib/fog/rackspace/queues.rb', line 199 def initialize(id, queue, client_id, data, ttl) @id, @queue, @producer_id = id, queue, client_id @data, @ttl = data, ttl @created = Time.now.to_i @claim = nil end |
Instance Attribute Details
#claim ⇒ Object
Returns the value of attribute claim.
196 197 198 |
# File 'lib/fog/rackspace/queues.rb', line 196 def claim @claim end |
#created ⇒ Object
Returns the value of attribute created.
196 197 198 |
# File 'lib/fog/rackspace/queues.rb', line 196 def created @created end |
#data ⇒ Object
Returns the value of attribute data.
195 196 197 |
# File 'lib/fog/rackspace/queues.rb', line 195 def data @data end |
#id ⇒ Object
Returns the value of attribute id.
195 196 197 |
# File 'lib/fog/rackspace/queues.rb', line 195 def id @id end |
#producer_id ⇒ Object
Returns the value of attribute producer_id.
195 196 197 |
# File 'lib/fog/rackspace/queues.rb', line 195 def producer_id @producer_id end |
#queue ⇒ Object
Returns the value of attribute queue.
195 196 197 |
# File 'lib/fog/rackspace/queues.rb', line 195 def queue @queue end |
#ttl ⇒ Object
Returns the value of attribute ttl.
195 196 197 |
# File 'lib/fog/rackspace/queues.rb', line 195 def ttl @ttl end |
Instance Method Details
#age ⇒ Integer
Determine how long ago this message was created, in seconds.
209 210 211 |
# File 'lib/fog/rackspace/queues.rb', line 209 def age Time.now.to_i - @created end |
#claimed? ⇒ Boolean
Return true if this message has been claimed.
223 224 225 |
# File 'lib/fog/rackspace/queues.rb', line 223 def claimed? ! @claim.nil? end |
#expired? ⇒ Boolean
Determine if this message has lived longer than its designated ttl.
230 231 232 |
# File 'lib/fog/rackspace/queues.rb', line 230 def expired? age > ttl end |
#extend_life ⇒ Object
Extend the #ttl of this message to include the lifetime of the claim it belongs to, plus the claim’s grace period.
236 237 238 239 240 |
# File 'lib/fog/rackspace/queues.rb', line 236 def extend_life return unless @claim extended = claim. - @created @ttl = extended if extended > @ttl end |
#href ⇒ String
Generate a URI segment that identifies this message.
216 217 218 |
# File 'lib/fog/rackspace/queues.rb', line 216 def href "#{PATH_BASE}/#{@queue.name}/messages/#{@id}" end |
#to_h ⇒ Hash
Convert this message to a GET payload.
245 246 247 248 249 250 251 252 |
# File 'lib/fog/rackspace/queues.rb', line 245 def to_h { "body" => @data, "age" => age, "ttl" => @ttl, "href" => href } end |