Class: Definition::ConformError
- Inherits:
-
Object
- Object
- Definition::ConformError
- Defined in:
- lib/definition/conform_error.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#definition ⇒ Object
Returns the value of attribute definition.
-
#i18n_key ⇒ Object
Returns the value of attribute i18n_key.
- #message ⇒ Object
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#sub_errors ⇒ Object
Returns the value of attribute sub_errors.
Instance Method Summary collapse
- #error_path ⇒ Object
-
#initialize(definition, message, sub_errors: [], i18n_key: definition.name) ⇒ ConformError
constructor
A new instance of ConformError.
- #json_pointer ⇒ Object
- #leaf_errors ⇒ Object
- #to_s ⇒ Object (also: #inspect)
- #translated_error(namespace = "definition", vars: {}) ⇒ Object
Constructor Details
#initialize(definition, message, sub_errors: [], i18n_key: definition.name) ⇒ ConformError
Returns a new instance of ConformError.
7 8 9 10 11 12 13 |
# File 'lib/definition/conform_error.rb', line 7 def initialize(definition, , sub_errors: [], i18n_key: definition.name) self.definition = definition self. = self.sub_errors = sub_errors self.i18n_key = i18n_key assign_parents end |
Instance Attribute Details
#definition ⇒ Object
Returns the value of attribute definition.
15 16 17 |
# File 'lib/definition/conform_error.rb', line 15 def definition @definition end |
#i18n_key ⇒ Object
Returns the value of attribute i18n_key.
15 16 17 |
# File 'lib/definition/conform_error.rb', line 15 def i18n_key @i18n_key end |
#message ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/definition/conform_error.rb', line 18 def if sub_errors.empty? @message else "#{@message}: { " + sub_errors.map(&:message).join(", ") + " }" end end |
#parent ⇒ Object
Returns the value of attribute parent.
15 16 17 |
# File 'lib/definition/conform_error.rb', line 15 def parent @parent end |
#sub_errors ⇒ Object
Returns the value of attribute sub_errors.
15 16 17 |
# File 'lib/definition/conform_error.rb', line 15 def sub_errors @sub_errors end |
Instance Method Details
#error_path ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# 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 ⇒ Object
43 44 45 |
# File 'lib/definition/conform_error.rb', line 43 def json_pointer "/#{error_path.join('/')}" end |
#leaf_errors ⇒ Object
47 48 49 50 51 |
# File 'lib/definition/conform_error.rb', line 47 def leaf_errors return [self] if sub_errors.empty? sub_errors.map(&:leaf_errors).flatten end |
#to_s ⇒ Object Also known as: inspect
26 27 28 |
# File 'lib/definition/conform_error.rb', line 26 def to_s "<Definition::ConformError \n\t message: \"#{}\", \n\t json_pointer: \"#{json_pointer}\">" end |
#translated_error(namespace = "definition", vars: {}) ⇒ Object
53 54 55 56 57 |
# 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 |