Sha256: 86bf1ae3ea2925be8bd41b2a28810c605d5bf410c0c7491910a3ffb6e8dde1d2
Contents?: true
Size: 815 Bytes
Versions: 10
Compression:
Stored size: 815 Bytes
Contents
# frozen_string_literal: true module Parametric class Top attr_reader :errors def initialize @errors = {} end def add_error(key, msg) errors[key] ||= [] errors[key] << msg end end class Context def initialize(path = nil, top = Top.new) @top = top @path = Array(path).compact end def errors top.errors end def add_error(msg) top.add_error(string_path, msg) end def add_base_error(key, msg) top.add_error(key, msg) end def sub(key) self.class.new(path + [key], top) end protected attr_reader :path, :top def string_path path.reduce(['$']) do |m, segment| m << (segment.is_a?(Integer) ? "[#{segment}]" : ".#{segment}") m end.join end end end
Version data entries
10 entries across 10 versions & 1 rubygems