class FakeSQS::Message

Attributes

approximate_first_receive_timestamp[R]
approximate_receive_count[R]
body[R]
delay_seconds[R]
id[R]
md5[R]
sender_id[R]
sent_timestamp[R]
visibility_timeout[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/fake_sqs/message.rb, line 11
def initialize(options = {})
  @body = options.fetch("MessageBody")
  @id = options.fetch("Id") { SecureRandom.uuid }
  @md5 = options.fetch("MD5") { Digest::MD5.hexdigest(@body) }
  @sender_id = options.fetch("SenderId") { SecureRandom.uuid.delete('-').upcase[0...21] }
  @approximate_receive_count = 0
  @sent_timestamp = Time.now.to_i * 1000
  @delay_seconds = options.fetch("DelaySeconds", 0).to_i
end

Public Instance Methods

attributes() click to toggle source
# File lib/fake_sqs/message.rb, line 47
def attributes
  {
    "SenderId" => sender_id,
    "ApproximateFirstReceiveTimestamp" => approximate_first_receive_timestamp,
    "ApproximateReceiveCount"=> approximate_receive_count,
    "SentTimestamp"=> sent_timestamp
  }
end
expire!() click to toggle source
# File lib/fake_sqs/message.rb, line 21
def expire!
  self.visibility_timeout = nil
end
expire_at(seconds) click to toggle source
# File lib/fake_sqs/message.rb, line 34
def expire_at(seconds)
  self.visibility_timeout = Time.now + seconds
end
expired?( limit = Time.now ) click to toggle source
# File lib/fake_sqs/message.rb, line 30
def expired?( limit = Time.now )
  self.visibility_timeout.nil? || self.visibility_timeout < limit
end
published?() click to toggle source
# File lib/fake_sqs/message.rb, line 38
def published?
  if self.delay_seconds && self.delay_seconds > 0
    elapsed_seconds = Time.now.to_i - (self.sent_timestamp.to_i / 1000)
    elapsed_seconds >= self.delay_seconds
  else
    true
  end
end
receipt() click to toggle source
# File lib/fake_sqs/message.rb, line 56
def receipt
  Digest::SHA1.hexdigest self.id
end
receive!() click to toggle source
# File lib/fake_sqs/message.rb, line 25
def receive!
  @approximate_first_receive_timestamp ||= Time.now.to_i * 1000
  @approximate_receive_count += 1
end