mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
creating flatten_json adapter
This commit is contained in:
18
lib/active_model/serializer/adapter/flatten_json.rb
Normal file
18
lib/active_model/serializer/adapter/flatten_json.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
require 'active_model/serializer/adapter/json/fragment_cache'
|
||||
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class Adapter
|
||||
class FlattenJson < Json
|
||||
def serializable_hash(options = {})
|
||||
super
|
||||
@result
|
||||
end
|
||||
end
|
||||
|
||||
def fragment_cache(cached_hash, non_cached_hash)
|
||||
Json::FragmentCache.new().fragment_cache(cached_hash, non_cached_hash)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -37,11 +37,7 @@ module ActiveModel
|
||||
@result = @core.merge @hash
|
||||
end
|
||||
|
||||
if root
|
||||
@result = { root => @result }
|
||||
else
|
||||
@result
|
||||
end
|
||||
{ root => @result }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user