Class: Interactors::Sequence

Inherits:
Object
  • Object
show all
Includes:
FunctionalInteractor, Kase
Defined in:
lib/interactors/sequence.rb

Overview

An Interactor that is a sequence of Interactors

Instance Method Summary collapse

Instance Method Details

#call(context = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/interactors/sequence.rb', line 18

def call(context = {})
  interactions.each do |interactor|
    results = interactor.call(context)
    next if results[0] == :ok
    return results if results[0] == :error
    raise ArgumentError, "Return value from interactor must be [:ok, context] or [:error, ...]"
  end
  [:ok, context]
end

#compose(interactor) ⇒ Object



13
14
15
16
# File 'lib/interactors/sequence.rb', line 13

def compose(interactor)
  interactions << interactor
  self
end

#interactionsObject



9
10
11
# File 'lib/interactors/sequence.rb', line 9

def interactions
  @__interactions ||= []
end