Sha256: 6f5b8d10f157057bae9bc6d86f1688d40a24ee8d93224b4e80ab940e02bd8b80
Contents?: true
Size: 713 Bytes
Versions: 14
Compression:
Stored size: 713 Bytes
Contents
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 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
14 entries across 14 versions & 1 rubygems