Adds support for meta attribute

Currently, 0.10.0.pre doesn't support `meta` option in `render`. This
way, there's no way to support features such as pagination. `0.9` had
this feature in place.

This adds support for it, as well as fixes small things in README.md.

This won't support `meta` in array responses because arrays don't have
keys, obviously. Also, the response should have a `root` key, otherwise
no `meta` will be included.

In some cases, for example using JsonApi, ArraySerializer will result in
a response with a `root`. In that case, `meta` will be included.
This commit is contained in:
Alexandre de Oliveira
2015-01-05 01:00:03 -02:00
parent 282de21984
commit bd27da1b76
7 changed files with 170 additions and 15 deletions

View File

@@ -114,11 +114,13 @@ module ActiveModel
name.demodulize.underscore.sub(/_serializer$/, '') if name
end
attr_accessor :object, :root
attr_accessor :object, :root, :meta, :meta_key
def initialize(object, options = {})
@object = object
@root = options[:root] || (self.class._root ? self.class.root_name : false)
@meta = options[:meta]
@meta_key = options[:meta_key]
end
def json_key