Class: Yes::Core::Commands::Response
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Yes::Core::Commands::Response
- Defined in:
- lib/yes/core/commands/response.rb
Direct Known Subclasses
Instance Method Summary collapse
- #as_json ⇒ Hash
-
#error_details ⇒ Hash
Error details in case an error occurred.
-
#success? ⇒ Boolean
True in case the command was processed successfully.
-
#to_notification ⇒ Hash
Command response as a hash.
-
#transaction ⇒ TransactionDetails?
Command’s transaction info if present.
-
#type ⇒ String
Type of the command response.
Instance Method Details
#as_json ⇒ Hash
57 58 59 |
# File 'lib/yes/core/commands/response.rb', line 57 def as_json(*) to_notification.as_json end |
#error_details ⇒ Hash
Returns error details in case an error occurred.
25 26 27 28 29 30 31 32 33 |
# File 'lib/yes/core/commands/response.rb', line 25 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 in case the command was processed successfully.
19 20 21 |
# File 'lib/yes/core/commands/response.rb', line 19 def success? error.blank? end |
#to_notification ⇒ Hash
Returns command response as a hash.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/yes/core/commands/response.rb', line 43 def to_notification error = success? ? {} : { error_details: } { type:, batch_id:, payload:, metadata:, command: cmd.class.name, id: cmd.command_id, transaction: transaction.to_h }.merge(error) end |
#transaction ⇒ TransactionDetails?
Returns command’s transaction info if present.
15 |
# File 'lib/yes/core/commands/response.rb', line 15 delegate :transaction, :batch_id, :payload, :metadata, to: :cmd |
#type ⇒ String
Returns type of the command response.
37 38 39 |
# File 'lib/yes/core/commands/response.rb', line 37 def type success? ? 'command_success' : 'command_error' end |