Class: Yes::Core::Commands::CommandGroupResponse
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Yes::Core::Commands::CommandGroupResponse
- Defined in:
- lib/yes/core/commands/command_group_response.rb
Overview
Response returned by Yes::Core::CommandHandling::CommandGroupHandler.
Mirrors the surface of Response (success?, error_details, type, to_notification) but carries an array of published events instead of a single one — one per sub-command in the group.
Instance Method Summary collapse
-
#as_json ⇒ Hash
JSON-friendly representation.
-
#error_details ⇒ Hash
Structured error info, or empty when successful.
-
#success? ⇒ Boolean
True when no error is attached.
-
#to_notification ⇒ Hash
Notification-shaped hash for downstream consumers.
-
#type ⇒ String
The response type tag.
Instance Method Details
#as_json ⇒ Hash
Returns JSON-friendly representation.
60 61 62 |
# File 'lib/yes/core/commands/command_group_response.rb', line 60 def as_json(*) to_notification.as_json end |
#error_details ⇒ Hash
Returns structured error info, or empty when successful.
30 31 32 33 34 35 36 37 38 |
# File 'lib/yes/core/commands/command_group_response.rb', line 30 def error_details return {} unless error { message: error., type: error.&.underscore&.tr(' ', '_'), extra: (error.extra if error.respond_to?(:extra) && error.extra.present?) }.compact end |
#success? ⇒ Boolean
Returns true when no error is attached.
25 26 27 |
# File 'lib/yes/core/commands/command_group_response.rb', line 25 def success? error.blank? end |
#to_notification ⇒ Hash
Returns notification-shaped hash for downstream consumers.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/yes/core/commands/command_group_response.rb', line 46 def to_notification error_payload = success? ? {} : { error_details: } { type:, batch_id:, payload:, metadata:, command: cmd.class.name, id: cmd.command_id, transaction: transaction.to_h }.merge(error_payload) end |
#type ⇒ String
Returns the response type tag.
41 42 43 |
# File 'lib/yes/core/commands/command_group_response.rb', line 41 def type success? ? 'command_success' : 'command_error' end |