Sha256: 7223f701668c33272190ee827f0fdc995b021ac55d13a53366c94be97e146691

Contents?: true

Size: 945 Bytes

Versions: 13

Compression:

Stored size: 945 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]))
          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

13 entries across 13 versions & 1 rubygems

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