Class: CallSheet::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/call_sheet/transaction.rb

Instance Method Summary collapse

Constructor Details

#initialize(steps) ⇒ Transaction

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Transaction.



10
11
12
# File 'lib/call_sheet/transaction.rb', line 10

def initialize(steps)
  @steps = steps
end

Instance Method Details

#call(input, options = {}, &block) ⇒ Object Also known as: []



15
16
17
18
19
20
21
22
23
24
# File 'lib/call_sheet/transaction.rb', line 15

def call(input, options = {}, &block)
  assert_valid_options(options)
  assert_options_satisfy_step_arity(options)

  steps = steps_with_options_applied(options)
  result = steps.inject(Right(input), :>>)

  block.call ResultMatcher.new(result) if block
  result
end

#subscribe(listeners) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/call_sheet/transaction.rb', line 28

def subscribe(listeners)
  if listeners.is_a?(Hash)
    listeners.each do |step_name, listener|
      steps.detect { |step| step.step_name == step_name }.subscribe(listener)
    end
  else
    steps.each do |step|
      step.subscribe(listeners)
    end
  end

  self
end