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

Defined Under Namespace

Classes: MessageArray

Instance Attribute Summary

Attributes inherited from Abstract

#left, #right

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

#initialize

Constructor Details

This class inherits a constructor from Dry::Schema::Message::Or::Abstract

Class Method Details

.handler(message) ⇒ Object

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.



38
39
40
# File 'lib/dry/schema/message/or/multi_path.rb', line 38

def self.handler(message)
  handlers.find { |k,| message.is_a?(k) }&.last
end

Instance Method Details

#_pathsObject

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.



71
72
73
# File 'lib/dry/schema/message/or/multi_path.rb', line 71

def _paths
  @paths ||= [Path[root]]
end

#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

#messagesObject

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.



56
57
58
# File 'lib/dry/schema/message/or/multi_path.rb', line 56

def messages
  @messages ||= _messages.flat_map { _1.to_or(root) }
end

#pathObject

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.



66
67
68
# File 'lib/dry/schema/message/or/multi_path.rb', line 66

def path
  root
end

#rootObject

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.



61
62
63
# File 'lib/dry/schema/message/or/multi_path.rb', line 61

def root
  @root ||= _messages.flat_map(&:_paths).reduce(:&)
end

#to_hObject



51
52
53
# File 'lib/dry/schema/message/or/multi_path.rb', line 51

def to_h
  @to_h ||= Path[[*root, :or]].to_h(messages.map(&:to_h))
end

#to_or(root) ⇒ Object

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.



76
77
78
# File 'lib/dry/schema/message/or/multi_path.rb', line 76

def to_or(root)
  self.root == root ? messages : [self]
end