Class: Ivy::Serializers::Documents::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/ivy/serializers/documents/document.rb

Direct Known Subclasses

IndividualResource, ResourceCollection

Instance Method Summary collapse

Constructor Details

#initialize(serializer, primary_resource_name, primary_resource) ⇒ Document

Returns a new instance of Document.



7
8
9
10
11
12
# File 'lib/ivy/serializers/documents/document.rb', line 7

def initialize(serializer, primary_resource_name, primary_resource)
  @serializer = serializer
  @primary_resource_name = primary_resource_name
  @primary_resource = primary_resource
  @included_resources = Hash.new { |hash, klass| hash[klass] = Set.new }
end

Instance Method Details

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



14
15
16
# File 'lib/ivy/serializers/documents/document.rb', line 14

def belongs_to(name, resource, options={})
  include_resource(resource) if resource && options[:embed_in_root]
end

#generate(generator) ⇒ Object



18
19
20
# File 'lib/ivy/serializers/documents/document.rb', line 18

def generate(generator)
  generator.document(self)
end

#generate_attributes(generator, resource) ⇒ Object



22
23
24
# File 'lib/ivy/serializers/documents/document.rb', line 22

def generate_attributes(generator, resource)
  @serializer.attributes(generator, resource)
end

#generate_included(generator) ⇒ Object



26
27
28
# File 'lib/ivy/serializers/documents/document.rb', line 26

def generate_included(generator)
  generator.included(self) unless @included_resources.empty?
end

#generate_included_resources(generator) ⇒ Object



30
31
32
# File 'lib/ivy/serializers/documents/document.rb', line 30

def generate_included_resources(generator)
  generator.included_resources(@included_resources)
end

#generate_relationships(generator, resource) ⇒ Object



34
35
36
# File 'lib/ivy/serializers/documents/document.rb', line 34

def generate_relationships(generator, resource)
  @serializer.relationships(generator, resource)
end

#generate_resource(generator, resource) ⇒ Object



38
39
40
# File 'lib/ivy/serializers/documents/document.rb', line 38

def generate_resource(generator, resource)
  @serializer.resource(generator, resource)
end

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



42
43
44
# File 'lib/ivy/serializers/documents/document.rb', line 42

def has_many(name, resources, options={})
  include_resources(resources) if options[:embed_in_root]
end