Sha256: 8a35706105a3085052cf7bf3db01a981062568903c4f90483d89b911d769f871

Contents?: true

Size: 952 Bytes

Versions: 10

Compression:

Stored size: 952 Bytes

Contents

# frozen_string_literal: true

require "dry/struct"
require "dry/schema/predicate_inferrer"
require "dry/schema/primitive_inferrer"
require "dry/schema/macros/dsl"
require "dry/schema/macros/hash"

module Dry
  module Schema
    module Macros
      Hash.prepend(::Module.new {
        def call(*args)
          if args.size >= 1 && args[0].is_a?(::Class) && args[0] <= ::Dry::Struct
            if block_given?
              raise ArgumentError, "blocks are not supported when using "\
                                   "a struct class (#{name.inspect} => #{args[0]})"
            end

            super(args[0].schema, *args.drop(1))
            type(schema_dsl.types[name].constructor(args[0].schema))
          else
            super
          end
        end
      })
    end

    PredicateInferrer::Compiler.send(:alias_method, :visit_struct, :visit_hash)
    PrimitiveInferrer::Compiler.send(:alias_method, :visit_struct, :visit_hash)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

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