README.md in restpack_serializer-0.5.7 vs README.md in restpack_serializer-0.5.8
- old
+ new
@@ -61,10 +61,12 @@
```ruby
class AlbumSerializer
include RestPack::Serializer
attributes :id, :title, :year, :artist_id, :extras
+ optional :score
+
can_include :artists, :songs
can_filter_by :year
def extras
if @context[:admin?]
@@ -76,10 +78,22 @@
```ruby
AlbumSerializer.as_json(album, { admin?: true })
```
+All `attributes` are serialized by default. If you'd like to skip an attribute, you can pass an option in the `@context` as follows:
+
+```ruby
+AlbumSerializer.as_json(album, { include_title?: false })
+```
+
+You can also define `optional` attributes which aren't included by default. To include:
+
+```ruby
+AlbumSerializer.as_json(album, { include_score?: true })
+```
+
## Exposing an API
The `AlbumSerializer` provides `page` and `resource` methods which provide paged collection and singular resource GET endpoints.
```ruby
@@ -112,11 +126,10 @@
```ruby
AlbumSerializer.page(params, Albums.where("year < 1950"), { admin?: true })
```
Other features:
- * [Dynamically Include/Exclude Attributes](https://github.com/RestPack/restpack_serializer/blob/master/spec/serializable/serializer_spec.rb#L42)
- * [Custom Attributes Hash](https://github.com/RestPack/restpack_serializer/blob/master/spec/serializable/serializer_spec.rb#L46)
+ * [Custom Attributes Hash](https://github.com/RestPack/restpack_serializer/blob/master/spec/serializable/serializer_spec.rb#L55)
## Paging
Collections are paged by default. `page` and `page_size` parameters are available: