Class: FakeSQS::Message
- Inherits:
-
Object
- Object
- FakeSQS::Message
- Defined in:
- lib/fake_sqs/message.rb
Instance Attribute Summary collapse
-
#approximate_first_receive_timestamp ⇒ Object
readonly
Returns the value of attribute approximate_first_receive_timestamp.
-
#approximate_receive_count ⇒ Object
readonly
Returns the value of attribute approximate_receive_count.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#delay_seconds ⇒ Object
readonly
Returns the value of attribute delay_seconds.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#md5 ⇒ Object
readonly
Returns the value of attribute md5.
-
#sender_id ⇒ Object
readonly
Returns the value of attribute sender_id.
-
#sent_timestamp ⇒ Object
readonly
Returns the value of attribute sent_timestamp.
-
#visibility_timeout ⇒ Object
Returns the value of attribute visibility_timeout.
Instance Method Summary collapse
- #attributes ⇒ Object
- #expire! ⇒ Object
- #expire_at(seconds) ⇒ Object
- #expired?(limit = Time.now) ⇒ Boolean
-
#initialize(options = {}) ⇒ Message
constructor
A new instance of Message.
- #published? ⇒ Boolean
- #receipt ⇒ Object
- #receive! ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Message
Returns a new instance of Message.
11 12 13 14 15 16 17 18 19 |
# File 'lib/fake_sqs/message.rb', line 11 def initialize( = {}) @body = .fetch("MessageBody") @id = .fetch("Id") { SecureRandom.uuid } @md5 = .fetch("MD5") { Digest::MD5.hexdigest(@body) } @sender_id = .fetch("SenderId") { SecureRandom.uuid.delete('-').upcase[0...21] } @approximate_receive_count = 0 @sent_timestamp = Time.now.to_i * 1000 @delay_seconds = .fetch("DelaySeconds", 0).to_i end |
Instance Attribute Details
#approximate_first_receive_timestamp ⇒ Object (readonly)
Returns the value of attribute approximate_first_receive_timestamp.
7 8 9 |
# File 'lib/fake_sqs/message.rb', line 7 def @approximate_first_receive_timestamp end |
#approximate_receive_count ⇒ Object (readonly)
Returns the value of attribute approximate_receive_count.
7 8 9 |
# File 'lib/fake_sqs/message.rb', line 7 def approximate_receive_count @approximate_receive_count end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/fake_sqs/message.rb', line 7 def body @body end |
#delay_seconds ⇒ Object (readonly)
Returns the value of attribute delay_seconds.
7 8 9 |
# File 'lib/fake_sqs/message.rb', line 7 def delay_seconds @delay_seconds end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/fake_sqs/message.rb', line 7 def id @id end |
#md5 ⇒ Object (readonly)
Returns the value of attribute md5.
7 8 9 |
# File 'lib/fake_sqs/message.rb', line 7 def md5 @md5 end |
#sender_id ⇒ Object (readonly)
Returns the value of attribute sender_id.
7 8 9 |
# File 'lib/fake_sqs/message.rb', line 7 def sender_id @sender_id end |
#sent_timestamp ⇒ Object (readonly)
Returns the value of attribute sent_timestamp.
7 8 9 |
# File 'lib/fake_sqs/message.rb', line 7 def @sent_timestamp end |
#visibility_timeout ⇒ Object
Returns the value of attribute visibility_timeout.
9 10 11 |
# File 'lib/fake_sqs/message.rb', line 9 def visibility_timeout @visibility_timeout end |
Instance Method Details
#attributes ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/fake_sqs/message.rb', line 47 def attributes { "SenderId" => sender_id, "ApproximateFirstReceiveTimestamp" => , "ApproximateReceiveCount"=> approximate_receive_count, "SentTimestamp"=> } end |
#expire! ⇒ Object
21 22 23 |
# File 'lib/fake_sqs/message.rb', line 21 def expire! self.visibility_timeout = nil end |
#expire_at(seconds) ⇒ Object
34 35 36 |
# File 'lib/fake_sqs/message.rb', line 34 def expire_at(seconds) self.visibility_timeout = Time.now + seconds end |
#expired?(limit = Time.now) ⇒ Boolean
30 31 32 |
# File 'lib/fake_sqs/message.rb', line 30 def expired?( limit = Time.now ) self.visibility_timeout.nil? || self.visibility_timeout < limit end |
#published? ⇒ Boolean
38 39 40 41 42 43 44 45 |
# 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..to_i / 1000) elapsed_seconds >= self.delay_seconds else true end end |
#receipt ⇒ Object
56 57 58 |
# File 'lib/fake_sqs/message.rb', line 56 def receipt Digest::SHA1.hexdigest self.id end |
#receive! ⇒ Object
25 26 27 28 |
# File 'lib/fake_sqs/message.rb', line 25 def receive! @approximate_first_receive_timestamp ||= Time.now.to_i * 1000 @approximate_receive_count += 1 end |