mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
s/side_load/embed_in_root
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user