module Dry::Schema::Extensions::Hints::MessageSetMethods

def initialize(messages, options = EMPTY_HASH)

Other tags:
    Api: - private
def initialize(messages, options = EMPTY_HASH)
  super
  @hints = messages.select(&:hint?)
  @failures = options.fetch(:failures, true)
end

def initialize_placeholders!

Other tags:
    Api: - private
def initialize_placeholders!
  @placeholders = unique_paths.each_with_object(EMPTY_HASH.dup) { |path, hash|
    curr_idx = 0
    last_idx = path.size - 1
    node = hash
    while curr_idx <= last_idx
      key = path[curr_idx]
      next_node =
        if node.is_a?(Array) && key.is_a?(Symbol)
          node_hash = (node << [] << {}).last
          node_hash[key] || (node_hash[key] = curr_idx < last_idx ? {} : [])
        else
          node[key] || (node[key] = curr_idx < last_idx ? {} : [])
        end
      node = next_node
      curr_idx += 1
    end
  }
end

def messages_map(messages = self.messages)

Other tags:
    Api: - private
def messages_map(messages = self.messages)
  return EMPTY_HASH if empty?
  messages.reduce(placeholders) { |hash, msg|
    node = msg.path.reduce(hash) { |a, e| a.is_a?(Hash) ? a[e] : a.last[e] }
    (node[0].is_a?(::Array) ? node[0] : node) << msg.dump
    hash
  }
end

def to_h

Other tags:
    Api: - public

Returns:
  • (HashArray>) -

Other tags:
    See: ResultMethods#hints -
    See: MessageSet#to_h -
def to_h
  @to_h ||= failures ? messages_map : messages_map(hints)
end

def unique_paths

Other tags:
    Api: - private
def unique_paths
  messages.uniq(&:path).map(&:path)
end