Closed GavinJoyce closed 9 years ago
@eugeneius, how about:
class PersonSerializer
include RestPack::Serializer
attributes :id, :name
optional_attributes :description
end
or
class PersonSerializer
include RestPack::Serializer
attributes :id, :name
optional :description
end
Adding them separately definitely reads better than flagging them inline as part of attributes
:+1:
What about using a similar API to mutations:
class PersonSerializer
include RestPack::Serializer
attributes :id, :name
optional do
attributes :description
end
end
That's nice however I think if I added support for that, the main API should become:
class PersonSerializer
include RestPack::Serializer
required do
attributes :id, :name
end
optional do
attributes :description
end
end
I think I'll keep it simple for now, I've almost got a PR ready
It's currently possible to do
serializer.as_json(model, { include_description?: false })
which will exclude thedescription
attribute. The default is to include the description.It would be nice to be able to easily set the default to not include the attribute. Something like:
serializer.as_json(model)
would exclude the descriptionserializer.as_json(model, { include_description?: false })
would exclude the descriptionserializer.as_json(model, { include_description?: true })
would include the description