class Crommand::Result(T)
- Crommand::Result(T)
- Reference
- Object
Overview
This class represents the results of running a command. It can be used to test the outcome of the command execution and retrieve errors in the case of failure.
Defined in:
result.crConstructors
-
.new(errors : Array(Error), value : T)
Create a Result instance with the errors and values specified.
-
.new(errors : Array(String), value : T)
Create a Result instance with the errors and values specified.
-
.new(errors : Array(Error))
Create a Result instance with the errors and values specified.
-
.new(errors : Array(String))
Create a Result instance with the errors and values specified.
-
.new(value : T)
Create a new Result instance with no errors and the value specified.
-
.new
Create a new Result instance with no errors and a nil value.
Class Method Summary
-
.fail(errors : Array(String))
Creates a Result with a value type of T from a set of errors.
Instance Method Summary
-
#errors : Array(Error)
Instance data.
-
#failed? : Bool
Tests whether a Result contains any errors.
-
#has_value? : Bool
Tests whether the result contains a returned value.
-
#if_set(&) : Result(T)
Invokes a supplied block, passing it the value returned through the result if a value has been set.
-
#if_unset(&) : Result(T)
Invokes a supplied block if a value has not been set.
-
#messages : Array(String)
Fetches a list of the error strings for a Result instance.
- #returned : Crommand::Optional(T)
-
#success? : Bool
Tests whether a Result contains no errors.
-
#value : T
Shortcut mechanism for accessing the value returned through the result.
-
#value? : T | Nil
Shortcut mechanism for accessing the value returned through the result.
Constructor Detail
Create a Result instance with the errors and values specified.
Create a Result instance with the errors and values specified.
Create a Result instance with the errors and values specified.
Create a Result instance with the errors and values specified.
Class Method Detail
Creates a Result with a value type of T from a set of errors.
Instance Method Detail
Invokes a supplied block, passing it the value returned through the result if a value has been set. Does nothing if a value has not been set.
Invokes a supplied block if a value has not been set. Does nothing if a value has been set.
Shortcut mechanism for accessing the value returned through the result. This will raise an exception if called for a result with no value.
Shortcut mechanism for accessing the value returned through the result. If the result has a value set then it will be returned, otherwise this method returns nil.