First try to implement ArraySerializer

This commit is contained in:
Tema Bolshakov
2014-08-28 19:16:24 +04:00
parent 1b718b6d48
commit c1fdfc1cdc
6 changed files with 46 additions and 45 deletions

21
test/fixtures/poro.rb vendored
View File

@@ -5,12 +5,16 @@ class Model
def read_attribute_for_serialization(name)
if name == :id || name == 'id'
object_id
id
else
@attributes[name]
end
end
def id
@attributes[:id] || @attributes['id'] || object_id
end
def method_missing(meth, *args)
if meth.to_s =~ /^(.*)=$/
@attributes[$1.to_sym] = args[0]
@@ -28,3 +32,18 @@ end
class ProfileSerializer < ActiveModel::Serializer
attributes :name, :description
end
Post = Class.new(Model)
Comment = Class.new(Model)
PostSerializer = Class.new(ActiveModel::Serializer) do
attributes :title, :body, :id
has_many :comments
end
CommentSerializer = Class.new(ActiveModel::Serializer) do
attributes :id, :body
belongs_to :post
end