Class: Dry::Transaction::ResultMatcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ ResultMatcher

Returns a new instance of ResultMatcher.



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

def initialize(result)
  @result = result
end

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



5
6
7
# File 'lib/dry/transaction/result_matcher.rb', line 5

def output
  @output
end

#resultObject (readonly)

Returns the value of attribute result.



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

def result
  @result
end

Instance Method Details

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



17
18
19
20
21
22
23
# File 'lib/dry/transaction/result_matcher.rb', line 17

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



11
12
13
14
15
# File 'lib/dry/transaction/result_matcher.rb', line 11

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

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