Class: Definition::ConformResult

Inherits:
Object
  • Object
show all
Defined in:
lib/definition/conform_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#valueObject (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_hashObject



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_messageObject



19
20
21
# File 'lib/definition/conform_result.rb', line 19

def error_message
  error_tree.map(&:message).join(", ")
end

#error_treeObject



48
49
50
# File 'lib/definition/conform_result.rb', line 48

def error_tree
  @conform_errors
end

#errorsObject



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_errorsObject



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?

Returns:



14
15
16
# File 'lib/definition/conform_result.rb', line 14

def passed?
  @conform_errors.empty?
end