Class: Definition::ConformResult
- Inherits:
-
Object
- Object
- Definition::ConformResult
- Defined in:
- lib/definition/conform_result.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #error_hash ⇒ Object
- #error_message ⇒ Object
- #error_tree ⇒ Object
- #errors ⇒ Object
-
#initialize(value, errors: []) ⇒ ConformResult
constructor
A new instance of ConformResult.
- #leaf_errors ⇒ Object
- #passed? ⇒ Boolean (also: #conformed?)
Constructor Details
#initialize(value, errors: []) ⇒ ConformResult
Returns a new instance of ConformResult.
7 8 9 10 |
# File 'lib/definition/conform_result.rb', line 7 def initialize(value, errors: []) @value = value @conform_errors = errors end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
12 13 14 |
# File 'lib/definition/conform_result.rb', line 12 def value @value end |
Instance Method Details
#error_hash ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/definition/conform_result.rb', line 33 def error_hash {}.tap do |error_hash| errors.each do |error| path_hash = if error.error_path.empty? { "" => error } else error.error_path.reverse .inject([error]) { |errors, key| { key => errors } } end merge_error_hash(error_hash, path_hash) end end end |
#error_message ⇒ Object
19 20 21 |
# File 'lib/definition/conform_result.rb', line 19 def error_tree.map(&:message).join(", ") end |
#error_tree ⇒ Object
48 49 50 |
# File 'lib/definition/conform_result.rb', line 48 def error_tree @conform_errors end |
#errors ⇒ Object
27 28 29 30 31 |
# File 'lib/definition/conform_result.rb', line 27 def errors leaf_errors.map do |error| find_next_parent_key_error(error) || error end.compact.uniq end |
#leaf_errors ⇒ Object
23 24 25 |
# File 'lib/definition/conform_result.rb', line 23 def leaf_errors @conform_errors.map(&:leaf_errors).flatten end |
#passed? ⇒ Boolean Also known as: conformed?
14 15 16 |
# File 'lib/definition/conform_result.rb', line 14 def passed? @conform_errors.empty? end |