s/side_load/embed_in_root

This commit is contained in:
Arthur Neves
2013-10-24 14:11:58 -04:00
parent 2b70503896
commit 860acad9af
7 changed files with 19 additions and 19 deletions

View File

@@ -19,14 +19,14 @@ module ActiveModel
def embed(type, options={})
CONFIG.embed = type
CONFIG.side_load = true if options[:side_load] || options[:include]
CONFIG.embed_in_root = true if options[:embed_in_root] || options[:include]
ActiveSupport::Deprecation.warn <<-WARN
** Notice: embed is deprecated. **
The use of .embed method on a Serializer will be soon removed, as this should have a global scope and not a class scope.
Please use the global .setup method instead:
ActiveModel::Serializer.setup do |config|
config.embed = :#{type}
config.side_load = #{CONFIG.side_load || false}
config.embed_in_root = #{CONFIG.embed_in_root || false}
end
WARN
end
@@ -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.side_load?
if association.embed_in_root?
hash[association.embedded_key] = serialize association
end
end

View File

@@ -7,14 +7,14 @@ module ActiveModel
def initialize(name, options={})
if options.has_key?(:include)
ActiveSupport::Deprecation.warn <<-WARN
** Notice: include was renamed to side_load. **
** Notice: include was renamed to embed_in_root. **
WARN
end
@name = name.to_s
@options = options
self.embed = options.fetch(:embed) { CONFIG.embed }
@side_load = options.fetch(:side_load) { options.fetch(:include) { CONFIG.side_load } }
@embed_in_root = options.fetch(:embed_in_root) { options.fetch(:include) { CONFIG.embed_in_root } }
@embed_key = options[:embed_key] || :id
@key = options[:key]
@embedded_key = options[:root] || name
@@ -23,10 +23,10 @@ module ActiveModel
end
attr_reader :name, :embed_ids, :embed_objects, :serializer_class
attr_accessor :side_load, :embed_key, :key, :embedded_key, :options
attr_accessor :embed_in_root, :embed_key, :key, :embedded_key, :options
alias embed_ids? embed_ids
alias embed_objects? embed_objects
alias side_load? side_load
alias embed_in_root? embed_in_root
def serializer_class=(serializer)
@serializer_class = serializer.is_a?(String) ? serializer.constantize : serializer