lib/dry/schema/macros/value.rb in dry-schema-1.3.2 vs lib/dry/schema/macros/value.rb in dry-schema-1.3.3

- old
+ new

@@ -15,12 +15,12 @@ if schema current_type = schema_dsl.types[name] updated_type = - if current_type.respond_to?(:of) - current_type.of(schema.type_schema) + if array?(current_type) + build_array_type(current_type, schema.type_schema) else schema.type_schema end schema_dsl.set_type(name, updated_type) @@ -35,9 +35,28 @@ type_spec = opts[:type_spec] each(type_spec.type.member) if type_spec.respond_to?(:member) self + end + + # @api private + def array?(type) + primitive_inferrer[type].eql?([::Array]) + end + + # @api private + def build_array_type(array_type, member) + if array_type.respond_to?(:of) + array_type.of(member) + else + raise ArgumentError, <<~ERROR.split("\n").join(' ') + Cannot define schema for a nominal array type. + Array types must be instances of Dry::Types::Array, + usually constructed with Types::Constructor(Array) { ... } or + Dry::Types['array'].constructor { ... } + ERROR + end end # @api private def respond_to_missing?(meth, include_private = false) super || meth.to_s.end_with?(QUESTION_MARK)