Sha256: 7407e6e9ed88817dcd83328ea3289a77e75238b0cd1fa2d9320c7e203556b902

Contents?: true

Size: 592 Bytes

Versions: 1

Compression:

Stored size: 592 Bytes

Contents

require 'dry/initializer'

module Dry
  module Schema
    # Used by the processors to coerce values in the input hash
    #
    # @api private
    class ValueCoercer
      extend Dry::Initializer

      # @api private
      param :type_schema

      # @api private
      def call(input)
        if input.success?
          type_schema[Hash(input)]
        else
          type_schema.member_types.reduce(EMPTY_HASH.dup) do |hash, (name, type)|
            hash[name] = input.error?(name) ? input[name] : type[input[name]]
            hash
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-schema-0.1.0 lib/dry/schema/value_coercer.rb