mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
Merge pull request #1132 from beauby/fix-flatten-json
Get rid of unnecessary instance variables, and implied dependencies.
This commit is contained in:
commit
b594d1487b
@ -1,7 +1,6 @@
|
|||||||
class ActiveModel::Serializer::Adapter::FlattenJson < ActiveModel::Serializer::Adapter::Json
|
class ActiveModel::Serializer::Adapter::FlattenJson < ActiveModel::Serializer::Adapter::Json
|
||||||
def serializable_hash(options = {})
|
def serializable_hash(options = {})
|
||||||
super
|
super.each_value.first
|
||||||
@result
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@ -5,11 +5,11 @@ class ActiveModel::Serializer::Adapter::Json < ActiveModel::Serializer::Adapter
|
|||||||
def serializable_hash(options = nil)
|
def serializable_hash(options = nil)
|
||||||
options ||= {}
|
options ||= {}
|
||||||
if serializer.respond_to?(:each)
|
if serializer.respond_to?(:each)
|
||||||
@result = serializer.map { |s| FlattenJson.new(s).serializable_hash(options) }
|
result = serializer.map { |s| FlattenJson.new(s).serializable_hash(options) }
|
||||||
else
|
else
|
||||||
@hash = {}
|
hash = {}
|
||||||
|
|
||||||
@core = cache_check(serializer) do
|
core = cache_check(serializer) do
|
||||||
serializer.attributes(options)
|
serializer.attributes(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -19,13 +19,13 @@ class ActiveModel::Serializer::Adapter::Json < ActiveModel::Serializer::Adapter
|
|||||||
|
|
||||||
if serializer.respond_to?(:each)
|
if serializer.respond_to?(:each)
|
||||||
array_serializer = serializer
|
array_serializer = serializer
|
||||||
@hash[association.key] = array_serializer.map do |item|
|
hash[association.key] = array_serializer.map do |item|
|
||||||
cache_check(item) do
|
cache_check(item) do
|
||||||
item.attributes(opts)
|
item.attributes(opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@hash[association.key] =
|
hash[association.key] =
|
||||||
if serializer && serializer.object
|
if serializer && serializer.object
|
||||||
cache_check(serializer) do
|
cache_check(serializer) do
|
||||||
serializer.attributes(options)
|
serializer.attributes(options)
|
||||||
@ -35,10 +35,10 @@ class ActiveModel::Serializer::Adapter::Json < ActiveModel::Serializer::Adapter
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@result = @core.merge @hash
|
result = core.merge hash
|
||||||
end
|
end
|
||||||
|
|
||||||
{ root => @result }
|
{ root => result }
|
||||||
end
|
end
|
||||||
|
|
||||||
def fragment_cache(cached_hash, non_cached_hash)
|
def fragment_cache(cached_hash, non_cached_hash)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user