Class: Ivy::Serializers::Formats::JSONAPI

Inherits:
JSON
  • Object
show all
Defined in:
lib/ivy/serializers/formats/json_api.rb

Instance Method Summary collapse

Methods inherited from JSON

#as_json, #attribute, #document, #id, #ids, #initialize, #resources, #type

Constructor Details

This class inherits a constructor from Ivy::Serializers::Formats::JSON

Instance Method Details

#attributes(resource) ⇒ Object



7
8
9
# File 'lib/ivy/serializers/formats/json_api.rb', line 7

def attributes(resource)
  @hash_gen.store_object(:attributes) { super }
end

#belongs_to(name, resource, options = {}) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/ivy/serializers/formats/json_api.rb', line 11

def belongs_to(name, resource, options={})
  if resource
    @hash_gen.store_object(name) { linkage(resource) }
  else
    @hash_gen.store(name, nil)
  end
end

#has_many(name, resources, options = {}) ⇒ Object



19
20
21
# File 'lib/ivy/serializers/formats/json_api.rb', line 19

def has_many(name, resources, options={})
  @hash_gen.store_object(name) { linkages(resources) }
end

#included(document) ⇒ Object



23
24
25
# File 'lib/ivy/serializers/formats/json_api.rb', line 23

def included(document)
  @hash_gen.store_array(:included) { super }
end

#included_resources(included_resources) ⇒ Object



27
28
29
# File 'lib/ivy/serializers/formats/json_api.rb', line 27

def included_resources(included_resources)
  included_resources.each_value { |resources| resources(resources) }
end

#primary_resource(primary_resource_name, primary_resource) ⇒ Object



31
32
33
# File 'lib/ivy/serializers/formats/json_api.rb', line 31

def primary_resource(primary_resource_name, primary_resource)
  super(:data, primary_resource)
end

#primary_resources(primary_resources_name, primary_resources) ⇒ Object



35
36
37
# File 'lib/ivy/serializers/formats/json_api.rb', line 35

def primary_resources(primary_resources_name, primary_resources)
  super(:data, primary_resources)
end

#relationships(document) ⇒ Object



39
40
41
# File 'lib/ivy/serializers/formats/json_api.rb', line 39

def relationships(document)
  @hash_gen.store_object(:relationships) { super }
end

#resource(resource) ⇒ Object



43
44
45
46
# File 'lib/ivy/serializers/formats/json_api.rb', line 43

def resource(resource)
  super
  type(:type, resource)
end