class Ivy::Serializers::Formats::ActiveModelSerializers

Public Instance Methods

belongs_to(name, resource, options={}) click to toggle source
# 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={}) click to toggle source
# 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) click to toggle source
Calls superclass method
# 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

Private Instance Methods

polymorphic_resource(resource) click to toggle source
# File lib/ivy/serializers/formats/active_model_serializers.rb, line 34
def polymorphic_resource(resource)
  id(:id, resource)
  type(:type, resource)
end
polymorphic_resources(resources) click to toggle source
# File lib/ivy/serializers/formats/active_model_serializers.rb, line 39
def polymorphic_resources(resources)
  resources.each { |resource| @hash_gen.push_object { polymorphic_resource(resource) } }
end
singularize(name) click to toggle source
# File lib/ivy/serializers/formats/active_model_serializers.rb, line 43
def singularize(name)
  Inflecto.singularize(name.to_s)
end