Class: PrettyApi::Errors::NestedErrors

Inherits:
Object
  • Object
show all
Defined in:
lib/pretty_api/errors/nested_errors.rb

Instance Method Summary collapse

Constructor Details

#initialize(nested_tree:) ⇒ NestedErrors

Returns a new instance of NestedErrors.



4
5
6
# File 'lib/pretty_api/errors/nested_errors.rb', line 4

def initialize(nested_tree:)
  @nested_tree = nested_tree
end

Instance Method Details

#parse(record) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/pretty_api/errors/nested_errors.rb', line 8

def parse(record)
  errors = record_only_errors(record)

  return errors if nested_tree.blank?

  parse_deep_nested_errors(record, nested_tree[record.class], errors)

  PrettyApi::Utils::Hash.deep_compact_blank(errors)
end