class Dry::Schema::Macros::Hash

Macro used to specify a nested schema

@api private

Public Instance Methods

call(*args, &block) click to toggle source

@api private

Calls superclass method
# File lib/dry/schema/macros/hash.rb, line 13
def call(*args, &block)
  if args.size >= 1 && args[0].respond_to?(:keys)
    hash_type = args[0]
    type_predicates = predicate_inferrer[hash_type]
    all_predicats = type_predicates + args.drop(1)

    super(*all_predicats) do
      hash_type.each do |key|
        if key.required?
          required(key.name).value(key.type)
        else
          optional(key.name).value(key.type)
        end
        instance_exec(&block) if block
      end
    end
  else
    trace << hash?

    super
  end
end