class Dry::Schema::MessageSet

@api public
@see Result#message_set
A set of messages used to generate errors

def self.[](messages, options = EMPTY_HASH)

Other tags:
    Api: - private
def self.[](messages, options = EMPTY_HASH)
  new(messages.flatten, options)
end

def [](key)

Other tags:
    Api: - public
def [](key)
  to_h[key]
end

def each(&block)

Other tags:
    Api: - public
def each(&block)
  return self if empty?
  return to_enum unless block
  messages.each(&block)
end

def empty?

Other tags:
    Api: - private
def empty?
  @empty ||= messages.empty?
end

def fetch(key)

Other tags:
    Api: - public
def fetch(key)
  self[key] || raise(KeyError, "+#{key}+ message was not found")
end

def freeze

Other tags:
    Api: - private
def freeze
  to_h
  empty?
  super
end

def initialize(messages, options = EMPTY_HASH)

Other tags:
    Api: - private
def initialize(messages, options = EMPTY_HASH)
  @messages = messages
  @options = options
  initialize_placeholders!
end

def initialize_placeholders!

Other tags:
    Api: - private
def initialize_placeholders!
  return @placeholders = EMPTY_HASH if empty?
  @placeholders = paths.reduce(EMPTY_HASH.dup) do |hash, path|
    curr_idx = 0
    last_idx = path.size - 1
    node = hash
    while curr_idx <= last_idx
      key = path[curr_idx]
      node = (node[key] || node[key] = curr_idx < last_idx ? {} : [])
      curr_idx += 1
    end
    hash
  end
end

def messages_map(messages = self.messages)

Other tags:
    Api: - private
def messages_map(messages = self.messages)
  return EMPTY_HASH if empty?
  messages.group_by(&:path).reduce(placeholders) do |hash, (path, msgs)|
    node = path.reduce(hash) { |a, e| a[e] }
    msgs.each do |msg|
      node << msg
    end
    node.map!(&:dump)
    hash
  end
end

def paths

Other tags:
    Api: - private
def paths
  @paths ||= messages.map(&:path).uniq
end

def to_h

Other tags:
    Api: - public
def to_h
  @to_h ||= messages_map
end