Sha256: f82c6b0d28becec48a9f7b4c224a5126849bcf2835bf23bed434dac09fee0306

Contents?: true

Size: 595 Bytes

Versions: 3

Compression:

Stored size: 595 Bytes

Contents

module Dry
  module Transaction
    class StepAdapters
      # @api private
      class Try
        include Dry::Monads::Either::Mixin

        def call(step, input, *args)
          unless step.options[:catch]
            raise ArgumentError, "+try+ steps require one or more exception classes provided via +catch:+"
          end

          Right(step.operation.call(input, *args))
        rescue *Array(step.options[:catch]) => e
          e = step.options[:raise].new(e.message) if step.options[:raise]
          Left(e)
        end
      end

      register :try, Try.new
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dry-transaction-0.10.2 lib/dry/transaction/step_adapters/try.rb
dry-transaction-0.10.1 lib/dry/transaction/step_adapters/try.rb
dry-transaction-0.10.0 lib/dry/transaction/step_adapters/try.rb