Module: Cuprum::Processing
- Included in:
- Command
- Defined in:
- lib/cuprum/processing.rb
Overview
Functional implementation for creating a command object. Cuprum::Processing defines a #call method, which performs the implementation defined by #process and returns an instance of Cuprum::Result.
Instance Method Summary collapse
-
#arity ⇒ Integer
Returns a nonnegative integer for commands that take a fixed number of arguments.
-
#build_errors ⇒ Array
Generates an empty errors object.
-
#call(*arguments, **keywords) { ... } ⇒ Cuprum::Result
Executes the command implementation and returns a Cuprum::Result or compatible object.
-
#process(*arguments, **keywords) { ... } ⇒ Object
The implementation of the command, to be executed when the #call method is called.
Instance Method Details
#arity ⇒ Integer
Returns a nonnegative integer for commands that take a fixed number of arguments. For commands that take a variable number of arguments, returns -n-1, where n is the number of required arguments.
69 70 71 |
# File 'lib/cuprum/processing.rb', line 69 def arity method(:process).arity end |
#build_errors ⇒ Array
Generates an empty errors object. When the command is called, the result will have its #errors property initialized to the value returned by #build_errors. By default, this is an array. If you want to use a custom errors object type, override this method in a subclass.
119 120 121 |
# File 'lib/cuprum/processing.rb', line 119 def build_errors [] end |
#call(*arguments, **keywords) { ... } ⇒ Cuprum::Result
99 100 101 102 103 |
# File 'lib/cuprum/processing.rb', line 99 def call *args, &block result = build_result(nil, :errors => build_errors) process_with_result(result, *args, &block) end |
#process(*arguments, **keywords) { ... } ⇒ Object
This is a private method.
161 162 163 |
# File 'lib/cuprum/processing.rb', line 161 def process *_args raise Cuprum::NotImplementedError, nil, caller(1..-1) end |