Class: Ivy::Serializers::Formats::ActiveModelSerializers

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

Instance Method Summary collapse

Methods inherited from JSON

#as_json, #attribute, #attributes, #document, #id, #ids, #included, #included_resources, #initialize, #primary_resources, #relationships, #resource, #resources, #type

Constructor Details

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

Instance Method Details

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



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ivy/serializers/formats/active_model_serializers.rb', line 8

def belongs_to(name, resource, options={})
  if options[:polymorphic]
    if resource
      @hash_gen.store_object(name) { polymorphic_resource(resource) }
    else
      @hash_gen.store(name, nil)
    end
  else
    id(:"#{name}_id", resource)
  end
end

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



20
21
22
23
24
25
26
# File 'lib/ivy/serializers/formats/active_model_serializers.rb', line 20

def has_many(name, resources, options={})
  if options[:polymorphic]
    @hash_gen.store_array(name) { polymorphic_resources(resources) }
  else
    ids(:"#{singularize(name)}_ids", resources)
  end
end

#primary_resource(primary_resource_name, primary_resource) ⇒ Object



28
29
30
# File 'lib/ivy/serializers/formats/active_model_serializers.rb', line 28

def primary_resource(primary_resource_name, primary_resource)
  super(singularize(primary_resource_name).to_sym, primary_resource)
end