Sha256: 46f950c02ad404b11deca63544b5f036158784f402206c66d467f7ad19206d9a

Contents?: true

Size: 929 Bytes

Versions: 10

Compression:

Stored size: 929 Bytes

Contents

# frozen_string_literal: true

require "dry/schema/macros/schema"

module Dry
  module Schema
    module Macros
      # Macro used to specify a nested schema
      #
      # @api private
      class Hash < Schema
        # @api private
        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
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dry-schema-1.10.6 lib/dry/schema/macros/hash.rb
dry-schema-1.10.5 lib/dry/schema/macros/hash.rb
dry-schema-1.10.4 lib/dry/schema/macros/hash.rb
dry-schema-1.10.3 lib/dry/schema/macros/hash.rb
dry-schema-1.10.2 lib/dry/schema/macros/hash.rb
dry-schema-1.10.1 lib/dry/schema/macros/hash.rb
dry-schema-1.9.3 lib/dry/schema/macros/hash.rb
dry-schema-1.9.2 lib/dry/schema/macros/hash.rb
dry-schema-1.9.1 lib/dry/schema/macros/hash.rb
dry-schema-1.9.0 lib/dry/schema/macros/hash.rb