class Definition::ConformError
Attributes
definition[RW]
i18n_key[RW]
message[W]
parent[RW]
sub_errors[RW]
Public Class Methods
new(definition, message, sub_errors: [], i18n_key: definition.name)
click to toggle source
# File lib/definition/conform_error.rb, line 7 def initialize(definition, message, sub_errors: [], i18n_key: definition.name) self.definition = definition self.message = message self.sub_errors = sub_errors self.i18n_key = i18n_key assign_parents end
Public Instance Methods
error_path()
click to toggle source
# File lib/definition/conform_error.rb, line 32 def error_path current = self path = current.is_a?(KeyConformError) ? [key] : [] while (current = current.parent) next unless current.is_a?(KeyConformError) path += [current.key] end path.reverse end
json_pointer()
click to toggle source
# File lib/definition/conform_error.rb, line 43 def json_pointer "/#{error_path.join('/')}" end
leaf_errors()
click to toggle source
# File lib/definition/conform_error.rb, line 47 def leaf_errors return [self] if sub_errors.empty? sub_errors.map(&:leaf_errors).flatten end
message()
click to toggle source
# File lib/definition/conform_error.rb, line 18 def message if sub_errors.empty? @message else "#{@message}: { " + sub_errors.map(&:message).join(", ") + " }" end end
to_s()
click to toggle source
# File lib/definition/conform_error.rb, line 26 def to_s "<Definition::ConformError \n\t message: \"#{message}\", \n\t json_pointer: \"#{json_pointer}\">" end
Also aliased as: inspect
translated_error(namespace = "definition", vars: {})
click to toggle source
# File lib/definition/conform_error.rb, line 53 def translated_error(namespace = "definition", vars: {}) namespace ||= "definition" vars[:key] = key if respond_to?(:key) ::I18n.t("#{namespace}.#{i18n_key}", definition.context.merge!(vars)) end
Private Instance Methods
assign_parents()
click to toggle source
# File lib/definition/conform_error.rb, line 61 def assign_parents sub_errors.each do |error| error.parent = self end end