Class: CubanLinx::Chain
- Inherits:
-
Object
- Object
- CubanLinx::Chain
- Defined in:
- lib/cuban_linx/chain.rb
Instance Method Summary collapse
- #call(status = :ok, messages = {}, errors = {}) ⇒ Object
-
#initialize(functions, context:) ⇒ Chain
constructor
A new instance of Chain.
Constructor Details
#initialize(functions, context:) ⇒ Chain
Returns a new instance of Chain.
3 4 5 6 7 |
# File 'lib/cuban_linx/chain.rb', line 3 def initialize(functions, context:) @function_chain = functions.map do |function| chainable_method(context, function) end end |
Instance Method Details
#call(status = :ok, messages = {}, errors = {}) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/cuban_linx/chain.rb', line 9 def call(status = :ok, = {}, errors = {}) Payload.new(status, , errors).then do |payload| function_chain.reduce(payload, &reducer).then do |result| block_given? ? yield(result) : result.tuple end end end |