lib/dry/schema/macros/value.rb in dry-schema-1.5.4 vs lib/dry/schema/macros/value.rb in dry-schema-1.5.5
- old
+ new
@@ -26,14 +26,18 @@
schema.type_schema
end
import_steps(schema)
- type(updated_type) unless custom_type? && !current_type.respond_to?(:of)
+ if !custom_type? || array_type?(current_type) || hash_type?(current_type)
+ type(updated_type)
+ elsif maybe_type?(current_type)
+ type(updated_type.optional)
+ end
end
- trace_opts = opts.reject { |key, _| key == :type_spec || key == :type_rule }
+ trace_opts = opts.reject { |key, _| %i[type_spec type_rule].include?(key) }
if (type_rule = opts[:type_rule])
trace.append(type_rule).evaluate(*predicates, **trace_opts)
trace.append(new(chain: false).instance_exec(&block)) if block
else
@@ -60,11 +64,17 @@
# @api private
def array_type?(type)
primitive_inferrer[type].eql?([::Array])
end
+ # @api private
def hash_type?(type)
primitive_inferrer[type].eql?([::Hash])
+ end
+
+ # @api private
+ def maybe_type?(type)
+ type.meta[:maybe].equal?(true)
end
# @api private
def build_array_type(array_type, member)
if array_type.respond_to?(:of)