Class: Takagi::EventBus::Message
- Inherits:
-
Object
- Object
- Takagi::EventBus::Message
- Defined in:
- lib/takagi/event_bus.rb,
sig/takagi/event_bus.rbs
Overview
Event message wrapper (shareable for Ractor)
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#reply_address ⇒ Object
readonly
Returns the value of attribute reply_address.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #deep_freeze(obj) ⇒ Object
-
#initialize(address, body, headers: {}, reply_address: nil, scope: Scope::DEFAULT, freeze_body: true) ⇒ Message
constructor
A new instance of Message.
-
#reply(body, headers: {}) ⇒ nil, untyped
Reply to this message (request-reply pattern).
Constructor Details
#initialize(address, body, headers: {}, reply_address: nil, scope: Scope::DEFAULT, freeze_body: true) ⇒ Message
Returns a new instance of Message.
36 37 38 39 40 41 42 43 |
# File 'lib/takagi/event_bus.rb', line 36 def initialize(address, body, headers: {}, reply_address: nil, scope: Scope::DEFAULT, freeze_body: true) @address = address.freeze @body = freeze_body ? deep_freeze(body) : body @headers = deep_freeze(headers) @reply_address = reply_address&.freeze @scope = Scope.normalize(scope) @timestamp = Time.now end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
34 35 36 |
# File 'lib/takagi/event_bus.rb', line 34 def address @address end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
34 35 36 |
# File 'lib/takagi/event_bus.rb', line 34 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
34 35 36 |
# File 'lib/takagi/event_bus.rb', line 34 def headers @headers end |
#reply_address ⇒ Object (readonly)
Returns the value of attribute reply_address.
34 35 36 |
# File 'lib/takagi/event_bus.rb', line 34 def reply_address @reply_address end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
34 35 36 |
# File 'lib/takagi/event_bus.rb', line 34 def scope @scope end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
34 35 36 |
# File 'lib/takagi/event_bus.rb', line 34 def @timestamp end |
Instance Method Details
#deep_freeze(obj) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/takagi/event_bus.rb', line 54 def deep_freeze(obj) case obj when Hash obj.transform_keys(&:freeze).transform_values { |v| deep_freeze(v) }.freeze when Array obj.map { |v| deep_freeze(v) }.freeze else # String, Symbol, Numeric, TrueClass, FalseClass, NilClass, and others obj.freeze end end |