Class: CubanLinx::Chain

Inherits:
Object
  • Object
show all
Defined in:
lib/cuban_linx/chain.rb

Instance Method Summary collapse

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, messages = {}, errors = {})
  Payload.new(status, messages, errors).then do |payload|
    function_chain.reduce(payload, &reducer).then do |result|
      block_given? ? yield(result) : result.tuple
    end
  end
end