Class: Grenache::Message
- Inherits:
-
Object
- Object
- Grenache::Message
- Defined in:
- lib/grenache/message.rb,
lib/grenache/request.rb
Overview
Store a single request information
Instance Attribute Summary collapse
-
#_ts ⇒ Object
Returns the value of attribute _ts.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #block_given? ⇒ Boolean
- #dump_payload ⇒ Object
-
#initialize(type, payload, opts = {}, &block) ⇒ Message
constructor
A new instance of Message.
- #qhash ⇒ Object
- #request? ⇒ Boolean
- #response? ⇒ Boolean
- #rid ⇒ Object
- #to_json ⇒ Object
- #yield(params = {}) ⇒ Object
Constructor Details
#initialize(type, payload, opts = {}, &block) ⇒ Message
Returns a new instance of Message.
8 9 10 11 12 13 14 |
# File 'lib/grenache/message.rb', line 8 def initialize(type, payload, opts={}, &block) @payload = payload @type = type @opts = opts @_ts = Time.now @block = block end |
Instance Attribute Details
#_ts ⇒ Object
Returns the value of attribute _ts.
6 7 8 |
# File 'lib/grenache/message.rb', line 6 def _ts @_ts end |
#opts ⇒ Object
Returns the value of attribute opts.
6 7 8 |
# File 'lib/grenache/message.rb', line 6 def opts @opts end |
#payload ⇒ Object
Returns the value of attribute payload.
6 7 8 |
# File 'lib/grenache/message.rb', line 6 def payload @payload end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/grenache/message.rb', line 6 def type @type end |
Instance Method Details
#block_given? ⇒ Boolean
16 17 18 |
# File 'lib/grenache/message.rb', line 16 def block_given? !!@block end |
#dump_payload ⇒ Object
32 33 34 |
# File 'lib/grenache/message.rb', line 32 def dump_payload @dump_payload ||= Oj.dump(payload) end |
#qhash ⇒ Object
28 29 30 |
# File 'lib/grenache/message.rb', line 28 def qhash "#{type}#{dump_payload}" end |
#request? ⇒ Boolean
15 16 17 |
# File 'lib/grenache/request.rb', line 15 def request? @type == 'req' end |
#response? ⇒ Boolean
19 20 21 |
# File 'lib/grenache/request.rb', line 19 def response? @type == 'res' end |
#rid ⇒ Object
24 25 26 |
# File 'lib/grenache/message.rb', line 24 def rid @rid ||= SecureRandom.uuid end |
#to_json ⇒ Object
36 37 38 |
# File 'lib/grenache/message.rb', line 36 def to_json Oj.dump([rid,type,payload]) end |
#yield(params = {}) ⇒ Object
20 21 22 |
# File 'lib/grenache/message.rb', line 20 def yield(params={}) @block.call(params) end |