Sha256: 11a22aaf024db797d03795dc363c3f394d1a4d172b653c94526e2b5fdac5c494

Contents?: true

Size: 642 Bytes

Versions: 2

Compression:

Stored size: 642 Bytes

Contents

module Dry
  module Types
    class Constrained
      class Coercible < Constrained
        # @param [Object] input
        # @param [#call] block
        # @yieldparam [Failure] failure
        # @yieldreturn [Result]
        # @return [Result]
        def try(input, &block)
          result = type.try(input)

          if result.success?
            validation = rule.(result.input)

            if validation.success?
              result
            else
              block ? yield(validation) : validation
            end
          else
            block ? yield(result) : result
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dry-types-0.9.4 lib/dry/types/constrained/coercible.rb
dry-types-0.9.3 lib/dry/types/constrained/coercible.rb