Implement ArraySerializer

This commit is contained in:
Santiago Pastorino
2013-08-19 16:55:03 -03:00
parent 61a1669a86
commit 7e83f0c29d
4 changed files with 58 additions and 1 deletions

View File

@@ -9,7 +9,11 @@ module ActiveModel
end
def serializer_for(resource)
"#{resource.class.name}Serializer".safe_constantize
if resource.respond_to?(:to_ary)
ArraySerializer
else
"#{resource.class.name}Serializer".safe_constantize
end
end
attr_accessor :_root, :_attributes, :_associations
@@ -114,6 +118,7 @@ module ActiveModel
hash = attributes
hash.merge! associations
end
alias serializable_object serializable_hash
def as_json(options={})
if root = options[:root] || self.root