Class: FakeSQS::Message

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Message

Returns a new instance of Message.



9
10
11
12
13
# File 'lib/fake_sqs/message.rb', line 9

def initialize(options = {})
  @body = options.fetch("MessageBody")
  @id = options.fetch("Id") { SecureRandom.uuid }
  @md5 = options.fetch("MD5") { Digest::MD5.hexdigest(@body) }
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/fake_sqs/message.rb', line 6

def body
  @body
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/fake_sqs/message.rb', line 6

def id
  @id
end

#md5Object (readonly)

Returns the value of attribute md5.



6
7
8
# File 'lib/fake_sqs/message.rb', line 6

def md5
  @md5
end

#visibility_timeoutObject

Returns the value of attribute visibility_timeout.



7
8
9
# File 'lib/fake_sqs/message.rb', line 7

def visibility_timeout
  @visibility_timeout
end

Instance Method Details

#attributesObject



27
28
29
30
31
32
33
# File 'lib/fake_sqs/message.rb', line 27

def attributes
  {
    "MessageBody" => body,
    "Id" => id,
    "MD5" => md5,
  }
end

#expire!Object



15
16
17
# File 'lib/fake_sqs/message.rb', line 15

def expire!
  self.visibility_timeout = nil
end

#expire_at(seconds) ⇒ Object



23
24
25
# File 'lib/fake_sqs/message.rb', line 23

def expire_at(seconds)
  self.visibility_timeout = Time.now + seconds
end

#expired?(limit = Time.now) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/fake_sqs/message.rb', line 19

def expired?( limit = Time.now )
  self.visibility_timeout.nil? || self.visibility_timeout < limit
end