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.
193 194 195 196 197 198 |
# File 'lib/fog/rackspace/queues.rb', line 193 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.
190 191 192 |
# File 'lib/fog/rackspace/queues.rb', line 190 def claim @claim end |
#created ⇒ Object
Returns the value of attribute created.
190 191 192 |
# File 'lib/fog/rackspace/queues.rb', line 190 def created @created end |
#data ⇒ Object
Returns the value of attribute data.
189 190 191 |
# File 'lib/fog/rackspace/queues.rb', line 189 def data @data end |
#id ⇒ Object
Returns the value of attribute id.
189 190 191 |
# File 'lib/fog/rackspace/queues.rb', line 189 def id @id end |
#producer_id ⇒ Object
Returns the value of attribute producer_id.
189 190 191 |
# File 'lib/fog/rackspace/queues.rb', line 189 def producer_id @producer_id end |
#queue ⇒ Object
Returns the value of attribute queue.
189 190 191 |
# File 'lib/fog/rackspace/queues.rb', line 189 def queue @queue end |
#ttl ⇒ Object
Returns the value of attribute ttl.
189 190 191 |
# File 'lib/fog/rackspace/queues.rb', line 189 def ttl @ttl end |
Instance Method Details
#age ⇒ Integer
Determine how long ago this message was created, in seconds.
203 204 205 |
# File 'lib/fog/rackspace/queues.rb', line 203 def age Time.now.to_i - @created end |
#claimed? ⇒ Boolean
Return true if this message has been claimed.
217 218 219 |
# File 'lib/fog/rackspace/queues.rb', line 217 def claimed? ! @claim.nil? end |
#expired? ⇒ Boolean
Determine if this message has lived longer than its designated ttl.
224 225 226 |
# File 'lib/fog/rackspace/queues.rb', line 224 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.
230 231 232 233 234 |
# File 'lib/fog/rackspace/queues.rb', line 230 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.
210 211 212 |
# File 'lib/fog/rackspace/queues.rb', line 210 def href "#{PATH_BASE}/#{@queue.name}/messages/#{@id}" end |
#to_h ⇒ Hash
Convert this message to a GET payload.
239 240 241 242 243 244 245 246 |
# File 'lib/fog/rackspace/queues.rb', line 239 def to_h { "body" => @data, "age" => age, "ttl" => @ttl, "href" => href } end |