class Crommand::Command(T)

Overview

Provides the base class for more concrete command classes. Command is a generic with the type parameter dictating the type that is returned as the value for the result generated when the command is executed.

Defined in:

command.cr

Instance Method Summary

Instance Method Detail

def execute : Crommand::Result(T) #

Derived classes should override this method to implement the actual functionality for the command. The output from this command should be a Result instance for the command execution. Generally you would not call this method directly but would instead call the #run() method which will perform validation and then invoke this method if and only if validation was successful.


[View source]
def fail(error : String) : Crommand::Result(T) #

Utility method generates a Crommand::Result failure value that can be used as a return value for the command execute() method.


[View source]
def fail(errors : Array(String)) : Crommand::Result(T) #

Utility method generates a Crommand::Result failure value that can be used as a return value for the command execute() method.


[View source]
def run : Crommand::Result(T) #

Called to run the command instance. Performs validation of the Command data before running the execute() method. Will not run the execute() method if validation returns any errors. This method should generally NOT be overridden by derived classes.


[View source]
def success(value : T) : Crommand::Result(T) #

Utility method generates a Crommand::Result success value that can be used as a return value for the command execute() method.


[View source]
def success : Crommand::Result(T) #

Utility method generates a Crommand::Result success value that can be used as a return value for the command execute() method. This method expects the command to have no returned value.


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

Derived classes should override this method to provide functionality that validates the data for the command. The output from this method will be an Array of Strings. If this Array is empty then validation will be considered to have succeeded. If the Array is not empty then validation will be considered to have failed and the String's contained in the Array will be used to create Crommand::Error instance for the Result generated.


[View source]