Sha256: bfd3d5543a16c6636f76b1e1f32fc674dde28b61aad88525315e65dd018de40f

Contents?: true

Size: 753 Bytes

Versions: 11

Compression:

Stored size: 753 Bytes

Contents

# frozen_string_literal: true

require 'dry/equalizer'
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
      include ::Dry::Equalizer(:type_schema)

      # @api private
      param :type_schema

      # @api private
      def call(input)
        if input.success?
          type_schema[input.to_h]
        else
          type_schema.each_with_object(EMPTY_HASH.dup) do |key, hash|
            name = key.name

            next unless input.key?(name)

            value = input[name]

            hash[name] = input.error?(name) ? value : key[value]
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
dry-schema-1.4.3 lib/dry/schema/value_coercer.rb
dry-schema-1.4.2 lib/dry/schema/value_coercer.rb
dry-schema-1.4.1 lib/dry/schema/value_coercer.rb
dry-schema-1.4.0 lib/dry/schema/value_coercer.rb
dry-schema-1.3.4 lib/dry/schema/value_coercer.rb
dry-schema-1.3.3 lib/dry/schema/value_coercer.rb
dry-schema-1.3.2 lib/dry/schema/value_coercer.rb
dry-schema-1.3.1 lib/dry/schema/value_coercer.rb
dry-schema-1.3.0 lib/dry/schema/value_coercer.rb
dry-schema-1.2.0 lib/dry/schema/value_coercer.rb
dry-schema-1.1.0 lib/dry/schema/value_coercer.rb