class Dry::Schema::Message::Or::MultiPath

A message type used by OR operations with different paths

@api public

Constants

MESSAGE_ARRAY_HANDLER

Public Class Methods

handler(message) click to toggle source

@api private

# File lib/dry/schema/message/or/multi_path.rb, line 40
def self.handler(message)
  case message
  when self
    IDENTITY
  when Array
    MESSAGE_ARRAY_HANDLER
  end
end

Public Instance Methods

_path() click to toggle source

@api private

# File lib/dry/schema/message/or/multi_path.rb, line 70
def _path
  @_path ||= Path[root]
end
_paths() click to toggle source

@api private

# File lib/dry/schema/message/or/multi_path.rb, line 75
def _paths
  @paths ||= _messages.flat_map(&:_paths)
end
hint?() click to toggle source

@api private

# File lib/dry/schema/extensions/hints.rb, line 35
def hint?
  false
end
messages() click to toggle source

@api private

# File lib/dry/schema/message/or/multi_path.rb, line 55
def messages
  @messages ||= _messages.flat_map { _1.to_or(root) }
end
path() click to toggle source

@api private

# File lib/dry/schema/message/or/multi_path.rb, line 65
def path
  root
end
root() click to toggle source

@api private

# File lib/dry/schema/message/or/multi_path.rb, line 60
def root
  @root ||= _paths.reduce(:&)
end
to_h() click to toggle source

@api public

# File lib/dry/schema/message/or/multi_path.rb, line 50
def to_h
  @to_h ||= Path[[*root, :or]].to_h(messages.map(&:to_h))
end
to_or(root) click to toggle source

@api private

# File lib/dry/schema/message/or/multi_path.rb, line 80
def to_or(root)
  self.root == root ? messages : [self]
end

Private Instance Methods

_messages() click to toggle source

@api private

# File lib/dry/schema/message/or/multi_path.rb, line 87
def _messages
  @_messages ||= [left, right].map do |message|
    handler = self.class.handler(message)

    unless handler
      raise ArgumentError,
            "#{message.inspect} is of unknown type #{message.class.inspect}"
    end

    handler.(message)
  end
end