mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
add support for root keys
remove debugging gem fix white space
This commit is contained in:
@@ -8,7 +8,7 @@ module ActiveModel
|
||||
|
||||
attr_reader :serializer
|
||||
|
||||
def initialize(serializer)
|
||||
def initialize(serializer, options = {})
|
||||
@serializer = serializer
|
||||
end
|
||||
|
||||
@@ -16,8 +16,14 @@ module ActiveModel
|
||||
raise NotImplementedError, 'This is an abstract method. Should be implemented at the concrete adapter.'
|
||||
end
|
||||
|
||||
def to_json(options={})
|
||||
serializable_hash(options).to_json
|
||||
def to_json(options = {})
|
||||
result = serializable_hash(options)
|
||||
|
||||
if root = options.fetch(:root, serializer.json_key)
|
||||
result = { root => result }
|
||||
end
|
||||
|
||||
result.to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user