Sha256: b8327a52a95418cbf71e32ddb1c2b5afef5149f15edcd7021cba84cb59e2b739

Contents?: true

Size: 807 Bytes

Versions: 8

Compression:

Stored size: 807 Bytes

Contents

# frozen_string_literal: true

require "dry/struct"

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

8 entries across 8 versions & 1 rubygems

Version Path
dry-schema-1.13.2 lib/dry/schema/extensions/struct.rb
dry-schema-1.13.1 lib/dry/schema/extensions/struct.rb
dry-schema-1.13.0 lib/dry/schema/extensions/struct.rb
dry-schema-1.12.0 lib/dry/schema/extensions/struct.rb
dry-schema-1.11.3 lib/dry/schema/extensions/struct.rb
dry-schema-1.11.2 lib/dry/schema/extensions/struct.rb
dry-schema-1.11.1 lib/dry/schema/extensions/struct.rb
dry-schema-1.11.0 lib/dry/schema/extensions/struct.rb