lib/dry/schema/message/or/multi_path.rb in dry-schema-1.8.0 vs lib/dry/schema/message/or/multi_path.rb in dry-schema-1.9.0

- old
+ new

@@ -15,20 +15,22 @@ class MultiPath < Abstract # @api private attr_reader :root # @api private - def initialize(*args) + def initialize(...) super - @root = [left, right].flatten.map(&:_path).reduce(:&) - @left = left.map { |msg| msg.to_or(root) } - @right = right.map { |msg| msg.to_or(root) } + flat_left = left.flatten + flat_right = right.flatten + @root = [*flat_left, *flat_right].map(&:_path).reduce(:&) + @left = flat_left.map { _1.to_or(root) } + @right = flat_right.map { _1.to_or(root) } end # @api public def to_h @to_h ||= Path[[*root, :or]].to_h( - [left.map(&:to_h).reduce(:merge), right.map(&:to_h).reduce(:merge)] + [MessageSet.new(left).to_h, MessageSet.new(right).to_h] ) end end end end