Sha256: faa8f2f9f9a77e0e2caa747f2b692c164fa3136e0a3c2e1fe32c0fe166e22922
Contents?: true
Size: 1.06 KB
Versions: 26
Compression:
Stored size: 1.06 KB
Contents
module Schemacop class Result attr_reader :current_path attr_reader :errors def initialize(root = nil, original_data = nil) @current_path = [] @errors = {} @root = root @original_data = original_data end def valid? errors.empty? end def data if errors.any? return nil else return @data ||= @root.cast(@original_data) end end def error(message) @errors[current_path] ||= [] @errors[current_path] << message end def messages_by_path @errors.transform_keys { |k| "/#{k.join('/')}" } end def exception_message messages.join("\n") end def messages messages = [] @errors.each do |path, path_messages| messages += path_messages.map do |path_message| "/#{path.join('/')}: #{path_message}" end end return messages end def in_path(segment) prev_path = @current_path @current_path += [segment] yield ensure @current_path = prev_path end end end
Version data entries
26 entries across 26 versions & 1 rubygems