Class: Dry::Schema::Message::Or::MultiPath

Inherits:
Abstract
  • Object
show all
Defined in:
lib/dry/schema/message/or/multi_path.rb,
lib/dry/schema/extensions/hints.rb

Overview

A message type used by OR operations with different paths

Instance Attribute Summary collapse

Attributes inherited from Abstract

#left, #right

Instance Method Summary collapse

Constructor Details

#initializeMultiPath

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MultiPath.



20
21
22
23
24
25
26
27
# File 'lib/dry/schema/message/or/multi_path.rb', line 20

def initialize(...)
  super
  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

Instance Attribute Details

#rootObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
# File 'lib/dry/schema/message/or/multi_path.rb', line 17

def root
  @root
end

Instance Method Details

#hint?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


35
36
37
# File 'lib/dry/schema/extensions/hints.rb', line 35

def hint?
  false
end

#to_hObject



30
31
32
33
34
# File 'lib/dry/schema/message/or/multi_path.rb', line 30

def to_h
  @to_h ||= Path[[*root, :or]].to_h(
    [MessageSet.new(left).to_h, MessageSet.new(right).to_h]
  )
end