Module: Cuprum::Processing
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 an indication of the number of arguments accepted by #call.
-
#call(*arguments, **keywords) { ... } ⇒ Cuprum::Result
Executes the command and returns a Cuprum::Result or compatible object.
-
#process(*arguments, **keywords) { ... } ⇒ Cuprum::Result, Object
The implementation of the command.
Instance Method Details
#arity ⇒ Integer
Returns an indication of the number of arguments accepted by #call.
If the method takes a fixed number N of arguments, returns N. If the method takes a variable number of arguments, returns -N-1, where N is the number of required arguments. Keyword arguments will be considered as a single additional argument, that argument being mandatory if any keyword argument is mandatory.
74 75 76 |
# File 'lib/cuprum/processing.rb', line 74 def arity method(:process).arity end |
#call(*arguments, **keywords) { ... } ⇒ Cuprum::Result
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/cuprum/processing.rb', line 98 def call(*args, **kwargs, &block) value = if kwargs.empty? process(*args, &block) else process(*args, **kwargs, &block) end return value.to_cuprum_result if value_is_result?(value) build_result(value: value) end |
#process(*arguments, **keywords) { ... } ⇒ Cuprum::Result, Object
136 137 138 139 140 |
# File 'lib/cuprum/processing.rb', line 136 def process(*_args) error = Cuprum::Errors::CommandNotImplemented.new(command: self) build_result(error: error) end |