Class: Yes::Core::Commands::Response

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/yes/core/commands/response.rb

Direct Known Subclasses

GroupResponse, Stateless::Response

Instance Method Summary collapse

Instance Method Details

#as_jsonHash

Returns:

  • (Hash)


57
58
59
# File 'lib/yes/core/commands/response.rb', line 57

def as_json(*)
  to_notification.as_json
end

#error_detailsHash

Returns error details in case an error occurred.

Returns:

  • (Hash)

    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.message,
    type: error.message&.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.

Returns:

  • (Boolean)

    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_notificationHash

Returns command response as a hash.

Returns:

  • (Hash)

    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

#transactionTransactionDetails?

Returns command’s transaction info if present.

Returns:



15
# File 'lib/yes/core/commands/response.rb', line 15

delegate :transaction, :batch_id, :payload, :metadata, to: :cmd

#typeString

Returns type of the command response.

Returns:

  • (String)

    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