Class: Domainic::Command::Result
- Inherits:
-
Object
- Object
- Domainic::Command::Result
- Defined in:
- lib/domainic/command/result.rb,
lib/domainic/command/result/status.rb,
lib/domainic/command/result/error_set.rb
Overview
A value object representing the outcome of a command execution. The Result class provides a consistent interface for handling both successful and failed command executions, including return data and error information.
Results are created through factory methods rather than direct instantiation, making the intent of the result clear:
Results use status codes that align with Unix exit codes, making them suitable for CLI applications:
- 0 - Successful execution
- 1 - Runtime failure
- 2 - Input validation failure
- 3 - Output validation failure
Defined Under Namespace
Modules: STATUS Classes: ErrorSet
Instance Attribute Summary collapse
-
#data ⇒ Struct
readonly
The structured data returned by the command.
-
#errors ⇒ ErrorSet
readonly
The errors that occurred during command execution.
-
#status_code ⇒ Integer
readonly
The status code indicating the result of the command execution.
Class Method Summary collapse
-
.failure(errors, context = {}, status: STATUS::FAILED_AT_RUNTIME) ⇒ Result
Creates a new failure result with the given status.
-
.failure_at_input(errors, context = {}) ⇒ Result
Creates a new input validation failure result.
-
.failure_at_output(errors, context = {}) ⇒ Result
Creates a new output validation failure result.
-
.success(context) ⇒ Result
Creates a new success result.
Instance Method Summary collapse
-
#failure? ⇒ Boolean
(also: #failed?)
Indicates whether the command failed.
-
#initialize(status_code, context: {}, errors: nil) ⇒ void
constructor
Creates a new result instance.
-
#successful? ⇒ Boolean
(also: #success?)
Indicates whether the command succeeded.
Constructor Details
#initialize(status_code, context: {}, errors: nil) ⇒ void
Creates a new result instance
117 118 119 120 121 |
# File 'lib/domainic/command/result.rb', line 117 def initialize(status_code, context: {}, errors: nil) initialize_status_code(status_code) initialize_data(context) @errors = ErrorSet.new(errors) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object (private)
Delegate method calls to the data struct
176 177 178 179 180 |
# File 'lib/domainic/command/result.rb', line 176 def method_missing(method_name, ...) return super unless respond_to_missing?(method_name) data.public_send(method_name.to_sym) end |
Instance Attribute Details
#data ⇒ Struct (readonly)
The structured data returned by the command
52 53 54 |
# File 'lib/domainic/command/result.rb', line 52 def data @data end |
#errors ⇒ ErrorSet (readonly)
The errors that occurred during command execution
57 58 59 |
# File 'lib/domainic/command/result.rb', line 57 def errors @errors end |
#status_code ⇒ Integer (readonly)
The status code indicating the result of the command execution
62 63 64 |
# File 'lib/domainic/command/result.rb', line 62 def status_code @status_code end |
Class Method Details
.failure(errors, context = {}, status: STATUS::FAILED_AT_RUNTIME) ⇒ Result
Creates a new failure result with the given status
72 73 74 |
# File 'lib/domainic/command/result.rb', line 72 def self.failure(errors, context = {}, status: STATUS::FAILED_AT_RUNTIME) new(status, context:, errors:) end |
.failure_at_input(errors, context = {}) ⇒ Result
Creates a new input validation failure result
83 84 85 |
# File 'lib/domainic/command/result.rb', line 83 def self.failure_at_input(errors, context = {}) new(STATUS::FAILED_AT_INPUT, context:, errors:) end |
.failure_at_output(errors, context = {}) ⇒ Result
Creates a new output validation failure result
94 95 96 |
# File 'lib/domainic/command/result.rb', line 94 def self.failure_at_output(errors, context = {}) new(STATUS::FAILED_AT_OUTPUT, context:, errors:) end |