Class: CallSheet::ResultMatcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ ResultMatcher

Returns a new instance of ResultMatcher.



6
7
8
# File 'lib/call_sheet/result_matcher.rb', line 6

def initialize(result)
  @result = result
end

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



4
5
6
# File 'lib/call_sheet/result_matcher.rb', line 4

def output
  @output
end

#resultObject (readonly)

Returns the value of attribute result.



3
4
5
# File 'lib/call_sheet/result_matcher.rb', line 3

def result
  @result
end

Instance Method Details

#failure(step_name = nil, &block) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/call_sheet/result_matcher.rb', line 16

def failure(step_name = nil, &block)
  return output unless result.is_a?(Kleisli::Either::Left)

  if step_name.nil? || step_name == result.value.__step_name
    @output = block.call(result.value)
  end
end

#success(&block) ⇒ Object



10
11
12
13
14
# File 'lib/call_sheet/result_matcher.rb', line 10

def success(&block)
  return output unless result.is_a?(Kleisli::Either::Right)

  @output = block.call(result.value)
end