Sha256: 88a02a5a8d6209e2ee8e02299c45bae2d86befa9ad86e589107c77bfbeefd01b

Contents?: true

Size: 588 Bytes

Versions: 6

Compression:

Stored size: 588 Bytes

Contents

require "dry/transaction/errors"

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

        def call(operation, options, args)
          unless options[:catch]
            raise MissingCatchListError.new(options[:step_name])
          end

          result = operation.(*args)
          Success(result)
        rescue *Array(options[:catch]) => e
          e = options[:raise].new(e.message) if options[:raise]
          Failure(e)
        end
      end

      register :try, Try.new
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dry-transaction-0.13.0 lib/dry/transaction/step_adapters/try.rb
dry-transaction-0.12.1 lib/dry/transaction/step_adapters/try.rb
dry-transaction-0.12.0 lib/dry/transaction/step_adapters/try.rb
dry-transaction-0.11.2 lib/dry/transaction/step_adapters/try.rb
dry-transaction-0.11.1 lib/dry/transaction/step_adapters/try.rb
dry-transaction-0.11.0 lib/dry/transaction/step_adapters/try.rb