Method: Avromatic::Model::Validation.missing_nested_attributes

Defined in:
lib/avromatic/model/validation.rb

.missing_nested_attributes(attribute, value) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/avromatic/model/validation.rb', line 11

def self.missing_nested_attributes(attribute, value)
  if value.is_a?(Array)
    results = []
    value.each_with_index do |element, index|
      nested_results = missing_nested_attributes("#{attribute}[#{index}]", element)
      results.concat(nested_results)
    end
    results
  elsif value.is_a?(Hash)
    results = []
    value.each do |key, element|
      nested_results = missing_nested_attributes("#{attribute}['#{key}']", element)
      results.concat(nested_results)
    end
    results
  elsif value.respond_to?(:missing_avro_attributes)
    value.missing_avro_attributes.map do |missing_child_attribute|
      "#{attribute}.#{missing_child_attribute}"
    end
  else
    EMPTY_ARRAY
  end
end