Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/active_model/serializer/adapter/flatten_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ class Serializer
class Adapter
class FlattenJson < Json
def serializable_hash(options = {})
super
@result
super.each_value.first
end

private
Expand Down
14 changes: 7 additions & 7 deletions lib/active_model/serializer/adapter/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ class Json < Adapter
def serializable_hash(options = nil)
options ||= {}
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
@hash = {}
hash = {}

@core = cache_check(serializer) do
core = cache_check(serializer) do
serializer.attributes(options)
end

Expand All @@ -21,13 +21,13 @@ def serializable_hash(options = nil)

if serializer.respond_to?(:each)
array_serializer = serializer
@hash[association.key] = array_serializer.map do |item|
hash[association.key] = array_serializer.map do |item|
cache_check(item) do
item.attributes(opts)
end
end
else
@hash[association.key] =
hash[association.key] =
if serializer && serializer.object
cache_check(serializer) do
serializer.attributes(options)
Expand All @@ -37,10 +37,10 @@ def serializable_hash(options = nil)
end
end
end
@result = @core.merge @hash
result = core.merge hash
end

{ root => @result }
{ root => result }
end

def fragment_cache(cached_hash, non_cached_hash)
Expand Down