Class: FastlyNsq::TestMessage
- Inherits:
-
Object
- Object
- FastlyNsq::TestMessage
- Defined in:
- lib/fastly_nsq/testing.rb
Overview
Stub for Nsq::Message used for testing. Use this class instead of a struct or test stubs when testing application logic that requires a Nsq::Message.
Instance Attribute Summary collapse
-
#attempts ⇒ Object
readonly
Returns the value of attribute attempts.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#raw_body ⇒ Object
readonly
Returns the value of attribute raw_body.
Instance Method Summary collapse
- #body ⇒ Object
- #finish ⇒ Object
-
#initialize(raw_body) ⇒ TestMessage
constructor
A new instance of TestMessage.
- #requeue ⇒ Object
Constructor Details
#initialize(raw_body) ⇒ TestMessage
Returns a new instance of TestMessage.
122 123 124 125 126 |
# File 'lib/fastly_nsq/testing.rb', line 122 def initialize(raw_body) @raw_body = raw_body @id = Digest::SHA1.hexdigest(raw_body.to_s + Time.now.to_s) @attempts = 0 end |
Instance Attribute Details
#attempts ⇒ Object (readonly)
Returns the value of attribute attempts.
119 120 121 |
# File 'lib/fastly_nsq/testing.rb', line 119 def attempts @attempts end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
120 121 122 |
# File 'lib/fastly_nsq/testing.rb', line 120 def id @id end |
#raw_body ⇒ Object (readonly)
Returns the value of attribute raw_body.
118 119 120 |
# File 'lib/fastly_nsq/testing.rb', line 118 def raw_body @raw_body end |
Instance Method Details
#body ⇒ Object
128 129 130 131 132 |
# File 'lib/fastly_nsq/testing.rb', line 128 def body JSON.parse(JSON.dump(raw_body)) rescue JSON::ParserError raw_body end |
#finish ⇒ Object
134 135 136 |
# File 'lib/fastly_nsq/testing.rb', line 134 def finish FastlyNsq::Messages..find { |_, ms| ms.delete(self) } end |
#requeue ⇒ Object
138 139 140 141 |
# File 'lib/fastly_nsq/testing.rb', line 138 def requeue(*) @attempts += 1 true end |