Sha256: b6e8dfd0ca1c2f202b30a730b0e0e664f659318e9627dfc0d7d49628220c26de

Contents?: true

Size: 488 Bytes

Versions: 2

Compression:

Stored size: 488 Bytes

Contents

module Dry
  module Transaction
    module StepAdapters
      # @api private
      class Try < Base
        def initialize(*)
          super
          raise ArgumentError, "+try+ steps require one or more exception classes provided via +catch:+" unless options[:catch]
        end

        def call(*args, input)
          Right(operation.call(*args, input))
        rescue *Array(options[:catch]) => e
          Left(e)
        end
      end

      register :try, Try
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dry-transaction-0.5.0 lib/dry/transaction/step_adapters/try.rb
dry-transaction-0.4.0 lib/dry/transaction/step_adapters/try.rb