Class: Dry::ResultMatcher::Matcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ Matcher

Returns a new instance of Matcher.



9
10
11
# File 'lib/dry/result_matcher/matcher.rb', line 9

def initialize(result)
  @result = result
end

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



7
8
9
# File 'lib/dry/result_matcher/matcher.rb', line 7

def output
  @output
end

#resultObject (readonly)

Returns the value of attribute result.



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

def result
  @result
end

Instance Method Details

#failure(&block) ⇒ Object



18
19
20
21
# File 'lib/dry/result_matcher/matcher.rb', line 18

def failure(&block)
  return output unless result.is_a?(Kleisli::Either::Left)
  @output = block.call(result.value)
end

#success(&block) ⇒ Object



13
14
15
16
# File 'lib/dry/result_matcher/matcher.rb', line 13

def success(&block)
  return output unless result.is_a?(Kleisli::Either::Right)
  @output = block.call(result.value)
end