Class: Jat::Plugins::JsonApi::Params::Include::Validate

Inherits:
Object
  • Object
show all
Defined in:
lib/jat/plugins/json_api/lib/params/include/validate.rb

Class Method Summary collapse

Class Method Details

.call(jat_class, includes) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/jat/plugins/json_api/lib/params/include/validate.rb', line 10

def call(jat_class, includes)
  includes.each do |name, nested_includes|
    attribute = jat_class.attributes[name]
    raise_error(jat_class, name) if !attribute || !attribute.relation?

    nested_serializer = attribute.serializer.call
    call(nested_serializer, nested_includes)
  end
end

.raise_error(jat_class, name) ⇒ Object

Raises:



20
21
22
# File 'lib/jat/plugins/json_api/lib/params/include/validate.rb', line 20

def raise_error(jat_class, name)
  raise Error, "#{jat_class} has no `#{name}` relationship"
end