embed_in_root is now side_load

This commit is contained in:
Santiago Pastorino
2013-10-24 14:57:41 -02:00
parent d26b7df158
commit 48db253765
7 changed files with 20 additions and 20 deletions

View File

@@ -147,7 +147,7 @@ end
included_associations = filter(associations.keys)
associations.each_with_object({}) do |(name, association), hash|
if included_associations.include? name
if association.embed_in_root?
if association.side_load?
hash[association.embedded_key] = serialize association
end
end

View File

@@ -5,22 +5,22 @@ module ActiveModel
class Serializer
class Association
def initialize(name, options={})
@name = name.to_s
@options = options
self.embed = options.fetch(:embed) { CONFIG.embed }
@embed_in_root = options.fetch(:include) { CONFIG.include }
@embed_key = options[:embed_key] || :id
@key = options[:key]
@embedded_key = options[:root] || name
@name = name.to_s
@options = options
self.embed = options.fetch(:embed) { CONFIG.embed }
@side_load = options.fetch(:include) { CONFIG.include }
@embed_key = options[:embed_key] || :id
@key = options[:key]
@embedded_key = options[:root] || name
self.serializer_class = @options[:serializer]
end
attr_reader :name, :embed_ids, :embed_objects, :serializer_class
attr_accessor :embed_in_root, :embed_key, :key, :embedded_key, :options
attr_accessor :side_load, :embed_key, :key, :embedded_key, :options
alias embed_ids? embed_ids
alias embed_objects? embed_objects
alias embed_in_root? embed_in_root
alias side_load? side_load
def serializer_class=(serializer)
@serializer_class = serializer.is_a?(String) ? serializer.constantize : serializer