Class: Yes::Core::Commands::CommandGroupResponse

Inherits:
Dry::Struct
  • Object
show all
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

Instance Method Details

#as_jsonHash

Returns JSON-friendly representation.

Returns:

  • (Hash)

    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_detailsHash

Returns structured error info, or empty when successful.

Returns:

  • (Hash)

    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.message,
    type: error.message&.underscore&.tr(' ', '_'),
    extra: (error.extra if error.respond_to?(:extra) && error.extra.present?)
  }.compact
end

#success?Boolean

Returns true when no error is attached.

Returns:

  • (Boolean)

    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_notificationHash

Returns notification-shaped hash for downstream consumers.

Returns:

  • (Hash)

    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

#typeString

Returns the response type tag.

Returns:

  • (String)

    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