class Crommand::Result(T)

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.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(errors : Array(Error), value : T) #

Create a Result instance with the errors and values specified.


[View source]
def self.new(errors : Array(String), value : T) #

Create a Result instance with the errors and values specified.


[View source]
def self.new(errors : Array(Error)) #

Create a Result instance with the errors and values specified.


[View source]
def self.new(errors : Array(String)) #

Create a Result instance with the errors and values specified.


[View source]
def self.new(value : T) #

Create a new Result instance with no errors and the value specified.


[View source]
def self.new #

Create a new Result instance with no errors and a nil value.


[View source]

Class Method Detail

def self.fail(errors : Array(String)) #

Creates a Result with a value type of T from a set of errors.


[View source]

Instance Method Detail

def errors : Array(Error) #

Instance data.


[View source]
def failed? : Bool #

Tests whether a Result contains any errors.


[View source]
def has_value? : Bool #

Tests whether the result contains a returned value.


[View source]
def if_set(&) : Result(T) #

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.


[View source]
def if_unset(&) : Result(T) #

Invokes a supplied block if a value has not been set. Does nothing if a value has been set.


[View source]
def messages : Array(String) #

Fetches a list of the error strings for a Result instance.


[View source]
def returned : Crommand::Optional(T) #

[View source]
def success? : Bool #

Tests whether a Result contains no errors.


[View source]
def value : T #

Shortcut mechanism for accessing the value returned through the result. This will raise an exception if called for a result with no value.


[View source]
def value? : T | Nil #

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.


[View source]