Deprecate include in favor of side_load

This commit is contained in:
Santiago Pastorino 2013-10-24 15:09:26 -02:00
parent 48db253765
commit cef6f85f44
4 changed files with 13 additions and 7 deletions

View File

@ -19,14 +19,14 @@ module ActiveModel
def embed(type, options={}) def embed(type, options={})
CONFIG.embed = type CONFIG.embed = type
CONFIG.include = true if options[:include] CONFIG.side_load = true if options[:side_load] || options[:include]
ActiveSupport::Deprecation.warn <<-WARN ActiveSupport::Deprecation.warn <<-WARN
** Notice: embed is deprecated. ** ** 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. 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: Please use the global .setup method instead:
ActiveModel::Serializer.setup do |config| ActiveModel::Serializer.setup do |config|
config.embed = :#{type} config.embed = :#{type}
config.include = #{CONFIG.include || false} config.side_load = #{CONFIG.side_load || false}
end end
WARN WARN
end end

View File

@ -5,10 +5,16 @@ module ActiveModel
class Serializer class Serializer
class Association class Association
def initialize(name, options={}) def initialize(name, options={})
if options.has_key?(:include)
ActiveSupport::Deprecation.warn <<-WARN
** Notice: include was renamed to side_load. **
WARN
end
@name = name.to_s @name = name.to_s
@options = options @options = options
self.embed = options.fetch(:embed) { CONFIG.embed } self.embed = options.fetch(:embed) { CONFIG.embed }
@side_load = options.fetch(:include) { CONFIG.include } @side_load = options.fetch(:side_load) { options.fetch(:include) { CONFIG.side_load } }
@embed_key = options[:embed_key] || :id @embed_key = options[:embed_key] || :id
@key = options[:key] @key = options[:key]
@embedded_key = options[:root] || name @embedded_key = options[:root] || name

View File

@ -40,7 +40,7 @@ module ActiveModel
def test_serialization_embedding_ids_including_in_root def test_serialization_embedding_ids_including_in_root
post_serializer = ARPostSerializer.new(@post) post_serializer = ARPostSerializer.new(@post)
embed(ARPostSerializer, embed: :ids, include: true) do embed(ARPostSerializer, embed: :ids, side_load: true) do
assert_equal({ assert_equal({
'ar_post' => { 'ar_post' => {
title: 'New post', body: 'A body!!!', title: 'New post', body: 'A body!!!',
@ -63,7 +63,7 @@ module ActiveModel
ARPostSerializer._associations.each_value do |association| ARPostSerializer._associations.each_value do |association|
association.embed = options[:embed] association.embed = options[:embed]
association.side_load = options[:include] association.side_load = options[:side_load]
end end
yield yield

View File

@ -66,7 +66,7 @@ module ActiveModel
class ApplyConfigTest < ActiveModel::TestCase class ApplyConfigTest < ActiveModel::TestCase
def test_apply_config_to_associations def test_apply_config_to_associations
CONFIG.embed = :ids CONFIG.embed = :ids
CONFIG.include = true CONFIG.side_load = true
association = PostSerializer._associations[:comments] association = PostSerializer._associations[:comments]
old_association = association.dup old_association = association.dup