Class: Cuprum::Function
- Inherits:
-
Object
- Object
- Cuprum::Function
- Defined in:
- lib/cuprum/function.rb
Overview
Functional object that encapsulates a business logic operation with a consistent interface and tracking of result value and status.
A Function can be defined either by passing a block to the constructor, or by defining a subclass of Function and implementing the #process method.
Direct Known Subclasses
Defined Under Namespace
Classes: NotImplementedError
Instance Method Summary collapse
-
#call(*arguments, *keywords) { ... } ⇒ Cuprum::Result
Executes the logic encoded in the constructor block, or the #process method if no block was passed to the constructor.
-
#initialize {|*arguments, **keywords, &block| ... } ⇒ Function
constructor
Returns a new instance of Cuprum::Function.
Constructor Details
#initialize {|*arguments, **keywords, &block| ... } ⇒ Function
Returns a new instance of Cuprum::Function.
82 83 84 |
# File 'lib/cuprum/function.rb', line 82 def initialize &implementation define_singleton_method :process, &implementation if implementation end |
Instance Method Details
#call(*arguments, *keywords) { ... } ⇒ Cuprum::Result
102 103 104 105 106 107 108 109 110 |
# File 'lib/cuprum/function.rb', line 102 def call *args, &block Cuprum::Result.new.tap do |result| @errors = result.errors result.value = process(*args, &block) @errors = nil end # tap end |