Class: RailwayIpc::IncomingMessage
- Inherits:
-
Object
- Object
- RailwayIpc::IncomingMessage
- Defined in:
- lib/railway_ipc/incoming_message.rb
Defined Under Namespace
Classes: InvalidMessage, ParserError
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#message_format ⇒ Object
readonly
Returns the value of attribute message_format.
-
#parsed_payload ⇒ Object
readonly
Returns the value of attribute parsed_payload.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #correlation_id ⇒ Object
- #decoded ⇒ Object
-
#initialize(payload, message_format: nil) ⇒ IncomingMessage
constructor
A new instance of IncomingMessage.
- #stringify_errors ⇒ Object
- #user_uuid ⇒ Object
- #uuid ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(payload, message_format: nil) ⇒ IncomingMessage
Returns a new instance of IncomingMessage.
7 8 9 10 11 12 13 14 15 |
# File 'lib/railway_ipc/incoming_message.rb', line 7 def initialize(payload, message_format: nil) @message_format = @parsed_payload = JSON.parse(payload) @type = parsed_payload['type'] @payload = payload @errors = {} rescue JSON::ParserError => e raise RailwayIpc::IncomingMessage::ParserError.new(e) end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'lib/railway_ipc/incoming_message.rb', line 5 def errors @errors end |
#message_format ⇒ Object (readonly)
Returns the value of attribute message_format.
5 6 7 |
# File 'lib/railway_ipc/incoming_message.rb', line 5 def @message_format end |
#parsed_payload ⇒ Object (readonly)
Returns the value of attribute parsed_payload.
5 6 7 |
# File 'lib/railway_ipc/incoming_message.rb', line 5 def parsed_payload @parsed_payload end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
5 6 7 |
# File 'lib/railway_ipc/incoming_message.rb', line 5 def payload @payload end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/railway_ipc/incoming_message.rb', line 5 def type @type end |
Instance Method Details
#correlation_id ⇒ Object
25 26 27 |
# File 'lib/railway_ipc/incoming_message.rb', line 25 def correlation_id decoded.correlation_id end |
#decoded ⇒ Object
35 36 37 38 |
# File 'lib/railway_ipc/incoming_message.rb', line 35 def decoded @decoded ||= \ get_decoder().call(type, parsed_payload['encoded_message']) end |
#stringify_errors ⇒ Object
40 41 42 |
# File 'lib/railway_ipc/incoming_message.rb', line 40 def stringify_errors errors.values.join(', ') end |
#user_uuid ⇒ Object
21 22 23 |
# File 'lib/railway_ipc/incoming_message.rb', line 21 def user_uuid decoded.user_uuid end |
#uuid ⇒ Object
17 18 19 |
# File 'lib/railway_ipc/incoming_message.rb', line 17 def uuid decoded.uuid end |
#valid? ⇒ Boolean
29 30 31 32 33 |
# File 'lib/railway_ipc/incoming_message.rb', line 29 def valid? errors[:uuid] = 'uuid is required' unless uuid.present? errors[:correlation_id] = 'correlation_id is required' unless correlation_id.present? errors.none? end |