Sha256: df6d762769b69d8ecaafef20f1ae30f6c2943ef0d3ac582f590ce648c81458c5

Contents?: true

Size: 944 Bytes

Versions: 13

Compression:

Stored size: 944 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(*args, &block)
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
dry-schema-1.8.0 lib/dry/schema/macros/hash.rb
dry-schema-1.7.1 lib/dry/schema/macros/hash.rb
dry-schema-1.7.0 lib/dry/schema/macros/hash.rb
dry-schema-1.6.2 lib/dry/schema/macros/hash.rb
dry-schema-1.6.1 lib/dry/schema/macros/hash.rb
dry-schema-1.6.0 lib/dry/schema/macros/hash.rb
dry-schema-1.5.6 lib/dry/schema/macros/hash.rb
dry-schema-1.5.5 lib/dry/schema/macros/hash.rb
dry-schema-1.5.4 lib/dry/schema/macros/hash.rb
dry-schema-1.5.3 lib/dry/schema/macros/hash.rb
dry-schema-1.5.2 lib/dry/schema/macros/hash.rb
dry-schema-1.5.1 lib/dry/schema/macros/hash.rb
dry-schema-1.5.0 lib/dry/schema/macros/hash.rb