Sha256: b792ecedbbda762fe8dfeca962e23c629d5b5421cb1d3de71879a18d0994252c

Contents?: true

Size: 702 Bytes

Versions: 10

Compression:

Stored size: 702 Bytes

Contents

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

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

            if validation.success?
              result
            else
              failure = failure(result.input, validation)
              block ? yield(failure) : failure
            end
          else
            block ? yield(result) : result
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dry-types-0.14.1 lib/dry/types/constrained/coercible.rb
dry-types-0.15.0 lib/dry/types/constrained/coercible.rb
dry-types-0.14.0 lib/dry/types/constrained/coercible.rb
dry-types-0.13.4 lib/dry/types/constrained/coercible.rb
dry-types-0.13.3 lib/dry/types/constrained/coercible.rb
dry-types-0.12.3 lib/dry/types/constrained/coercible.rb
dry-types-0.13.2 lib/dry/types/constrained/coercible.rb
dry-types-0.13.1 lib/dry/types/constrained/coercible.rb
dry-types-0.13.0 lib/dry/types/constrained/coercible.rb
dry-types-0.12.2 lib/dry/types/constrained/coercible.rb