Class: Jat::Plugins::SimpleApiValidateParams::ValidateFieldsParam

Inherits:
Object
  • Object
show all
Defined in:
lib/jat/plugins/simple_api/plugins/simple_api_validate_params/lib/validate_fields_param.rb

Class Method Summary collapse

Class Method Details

.call(jat_class, fields, prev_names = []) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/jat/plugins/simple_api/plugins/simple_api_validate_params/lib/validate_fields_param.rb', line 8

def call(jat_class, fields, prev_names = [])
  fields.each do |name, nested_fields|
    attribute = jat_class.attributes[name]

    raise_error(name, prev_names) unless attribute
    next if nested_fields.empty?

    raise_nested_error(name, prev_names, nested_fields) unless attribute.relation?
    nested_serializer = attribute.serializer.call
    call(nested_serializer, nested_fields, prev_names + [name])
  end
end