Sha256: 023a68b46ba6e5387c635f60a1037cd7ec38f897f5545fd47f29b1c6a2f90a47

Contents?: true

Size: 582 Bytes

Versions: 3

Compression:

Stored size: 582 Bytes

Contents

module Dry
  module Transaction
    class ResultMatcher
      attr_reader :result
      attr_reader :output

      def initialize(result)
        @result = result
      end

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

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

      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
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dry-transaction-0.6.0 lib/dry/transaction/result_matcher.rb
dry-transaction-0.5.0 lib/dry/transaction/result_matcher.rb
dry-transaction-0.4.0 lib/dry/transaction/result_matcher.rb