Class: Verquest::Result
- Inherits:
-
Object
- Object
- Verquest::Result
- Defined in:
- lib/verquest/result.rb
Overview
A result object for operation outcomes
Result represents the outcome of an operation in the Verquest gem, particularly parameter mapping and validation operations. It follows the Result pattern, providing a consistent interface for both successful and failed operations, avoiding exceptions for control flow.
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#success ⇒ Boolean
readonly
Whether the operation was successful.
-
#value ⇒ Object?
readonly
The result value if successful, nil otherwise.
Class Method Summary collapse
-
.failure(errors) ⇒ Result
Create a failed result with errors.
-
.success(value) ⇒ Result
Create a successful result with a value.
Instance Method Summary collapse
-
#failure? ⇒ Boolean
Check if the result represents a failed operation.
-
#initialize(success:, value: nil, errors: nil) ⇒ Result
constructor
Initialize a new Result instance.
-
#success? ⇒ Boolean
Check if the result represents a successful operation.
Constructor Details
#initialize(success:, value: nil, errors: nil) ⇒ Result
Initialize a new Result instance
39 40 41 42 43 |
# File 'lib/verquest/result.rb', line 39 def initialize(success:, value: nil, errors: nil) @success = success @value = value @errors = errors end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
31 |
# File 'lib/verquest/result.rb', line 31 attr_reader :success, :value, :errors |
#success ⇒ Boolean (readonly)
Returns Whether the operation was successful.
31 32 33 |
# File 'lib/verquest/result.rb', line 31 def success @success end |
#value ⇒ Object? (readonly)
Returns The result value if successful, nil otherwise.
31 |
# File 'lib/verquest/result.rb', line 31 attr_reader :success, :value, :errors |
Class Method Details
.failure(errors) ⇒ Result
Create a failed result with errors
57 58 59 |
# File 'lib/verquest/result.rb', line 57 def self.failure(errors) new(success: false, errors: errors) end |
.success(value) ⇒ Result
Create a successful result with a value
49 50 51 |
# File 'lib/verquest/result.rb', line 49 def self.success(value) new(success: true, value: value) end |
Instance Method Details
#failure? ⇒ Boolean
Check if the result represents a failed operation
71 72 73 |
# File 'lib/verquest/result.rb', line 71 def failure? !success end |
#success? ⇒ Boolean
Check if the result represents a successful operation
64 65 66 |
# File 'lib/verquest/result.rb', line 64 def success? success end |