Class: LSQS::Message
- Inherits:
-
Object
- Object
- LSQS::Message
- Defined in:
- lib/lsqs/message.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#md5 ⇒ Object
readonly
Returns the value of attribute md5.
-
#visibility_timeout ⇒ Object
Returns the value of attribute visibility_timeout.
Instance Method Summary collapse
- #attributes ⇒ Object
-
#expire ⇒ NilClass
Resets the visibility time of the message.
-
#expire_in(seconds) ⇒ Time
Sets the time when the message should expire.
-
#expired? ⇒ TrueClass|FalseClass
Check if a message’s visibility has timed out.
-
#initialize(options = {}) ⇒ Message
constructor
A new instance of Message.
Constructor Details
#initialize(options = {}) ⇒ Message
Returns a new instance of Message.
6 7 8 9 10 |
# File 'lib/lsqs/message.rb', line 6 def initialize( = {}) @body = ['MessageBody'] || '' @id = .fetch('Id') { SecureRandom.uuid } @md5 = .fetch('MD5') { Digest::MD5.hexdigest(body) } end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/lsqs/message.rb', line 3 def body @body end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/lsqs/message.rb', line 3 def id @id end |
#md5 ⇒ Object (readonly)
Returns the value of attribute md5.
3 4 5 |
# File 'lib/lsqs/message.rb', line 3 def md5 @md5 end |
#visibility_timeout ⇒ Object
Returns the value of attribute visibility_timeout.
4 5 6 |
# File 'lib/lsqs/message.rb', line 4 def visibility_timeout @visibility_timeout end |
Instance Method Details
#attributes ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/lsqs/message.rb', line 12 def attributes { "MessageBody" => body, "Id" => id, "MD5" => md5, } end |
#expire ⇒ NilClass
Resets the visibility time of the message.
45 46 47 |
# File 'lib/lsqs/message.rb', line 45 def expire @visibility_timeout = nil end |
#expire_in(seconds) ⇒ Time
Sets the time when the message should expire.
36 37 38 |
# File 'lib/lsqs/message.rb', line 36 def expire_in(seconds) @visibility_timeout = Time.now + seconds end |
#expired? ⇒ TrueClass|FalseClass
Check if a message’s visibility has timed out.
25 26 27 |
# File 'lib/lsqs/message.rb', line 25 def expired? visibility_timeout.nil? || visibility_timeout < Time.now end |