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_context ⇒ Object
Returns the value of attribute i18n_context.
-
#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.
- #translated_error(namespace = "definition") ⇒ Object
Instance Method Summary collapse
- #error_path ⇒ Object
-
#initialize(definition, message, sub_errors: [], **options) ⇒ ConformError
constructor
A new instance of ConformError.
- #json_pointer ⇒ Object
- #leaf_errors ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(definition, message, sub_errors: [], **options) ⇒ ConformError
Returns a new instance of ConformError.
7 8 9 10 11 12 13 14 15 |
# File 'lib/definition/conform_error.rb', line 7 def initialize(definition, , sub_errors: [], **) self.definition = definition self. = self.sub_errors = sub_errors self.i18n_key = .fetch(:i18n_key, definition.name) self.i18n_context = .fetch(:i18n_context, {}) self.translated_error = .fetch(:translated_message, nil) assign_parents end |
Instance Attribute Details
#definition ⇒ Object
Returns the value of attribute definition.
17 18 19 |
# File 'lib/definition/conform_error.rb', line 17 def definition @definition end |
#i18n_context ⇒ Object
Returns the value of attribute i18n_context.
17 18 19 |
# File 'lib/definition/conform_error.rb', line 17 def i18n_context @i18n_context end |
#i18n_key ⇒ Object
Returns the value of attribute i18n_key.
17 18 19 |
# File 'lib/definition/conform_error.rb', line 17 def i18n_key @i18n_key end |
#message ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/definition/conform_error.rb', line 20 def if sub_errors.empty? @message else "#{@message}: { " + sub_errors.map(&:message).join(", ") + " }" end end |
#parent ⇒ Object
Returns the value of attribute parent.
17 18 19 |
# File 'lib/definition/conform_error.rb', line 17 def parent @parent end |
#sub_errors ⇒ Object
Returns the value of attribute sub_errors.
17 18 19 |
# File 'lib/definition/conform_error.rb', line 17 def sub_errors @sub_errors end |
#translated_error(namespace = "definition") ⇒ Object
55 56 57 |
# File 'lib/definition/conform_error.rb', line 55 def translated_error(namespace = "definition") @translated_error ||= definition.error_renderer.new(self, i18n_namespace: namespace).translated_error end |
Instance Method Details
#error_path ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/definition/conform_error.rb', line 34 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
45 46 47 |
# File 'lib/definition/conform_error.rb', line 45 def json_pointer "/#{error_path.join('/')}" end |
#leaf_errors ⇒ Object
49 50 51 52 53 |
# File 'lib/definition/conform_error.rb', line 49 def leaf_errors return [self] if sub_errors.empty? sub_errors.map(&:leaf_errors).flatten end |
#to_s ⇒ Object Also known as: inspect
28 29 30 |
# File 'lib/definition/conform_error.rb', line 28 def to_s "<Definition::ConformError \n\t message: \"#{}\", \n\t json_pointer: \"#{json_pointer}\">" end |