README.md in alba-0.4.0 vs README.md in alba-0.5.0
- old
+ new
@@ -106,9 +106,25 @@
UserResource1.new(user).serialize
# => '{"id":1,"articles":[{"title":"Hello World!"},{"title":"Super nice"}]}'
```
+### Inline definition with `Alba.serialize`
+
+`Alba.serialize` method is a shortcut to define everything inline.
+
+```ruby
+Alba.serialize(user, with: proc { set key: :foo }) do
+ attributes :id
+ many :articles do
+ attributes :title, :body
+ end
+end
+# => '{"foo":{"id":1,"articles":[{"title":"Hello World!","body":"Hello World!!!"},{"title":"Super nice","body":"Really nice!"}]}}'
+```
+
+Although this might be useful sometimes, it's generally recommended to define a class for both Resource and Serializer.
+
## Comparison
Since Alba is intended to be stupid, there are many things Alba can't do while other gems can. However, from the same reason, it's extremely faster than alternatives.
For a performance benchmark, see https://gist.github.com/okuramasafumi/4e375525bd3a28e4ca812d2a3b3e5829.