Class: Dry::Schema::Macros::Hash Private

Inherits:
Dry::Schema show all
Defined in:
lib/dry/schema/macros/hash.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Macro used to specify a nested schema

Constant Summary

Constants included from Dry::Schema

DEFAULT_MESSAGES_PATH, DEFAULT_MESSAGES_ROOT, DOT, InvalidSchemaError, LIST_SEPARATOR, Dry::Schema::MissingMessageError, QUESTION_MARK, STEPS_IN_ORDER, VERSION

Instance Method Summary collapse

Methods included from Dry::Schema

JSON, Params, config, define, loader

Instance Method Details

#call(*args, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dry/schema/macros/hash.rb', line 11

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