add support for root keys

remove debugging gem

fix white space
This commit is contained in:
NullVoxPopuli
2014-10-12 21:51:41 -04:00
parent 97023db904
commit 7338b62b02
5 changed files with 54 additions and 15 deletions

View File

@@ -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

View File

@@ -13,6 +13,7 @@ module ActiveModel
@hash[name] = association.attributes(options)
end
end
@hash
end
end