README.md in uber-0.0.12 vs README.md in uber-0.0.13
- old
+ new
@@ -195,10 +195,14 @@
# Builder
When included, `Builder` allows to add builder instructions on the class level. These can then be evaluated when instantiating
the class to conditionally build (sub-)classes based on the incoming parameters.
+Builders can be defined in two different ways.
+
+## Block Syntax
+
```ruby
class Listener
include Uber::Builder
builds do |params|
@@ -225,9 +229,24 @@
```ruby
Listener.build({}) #=> Listener
Listener.build({current_user: @current_user}) #=> SignedIn
```
+
+## Proc Syntax
+
+Setting up builders using the proc syntax allows to call `return` in the block. This is our preferred way to define builders.
+
+```ruby
+build ->(params) do
+ return SignedIn if params[:current_user]
+ return Admin if params[:admin]
+ Default
+end
+```
+
+This makes the block extremely readable.
+
Note that builders are _not_ inherited to subclasses. This allows instantiating subclasses directly without running builders.
This pattern is used in [Cells](https://github.com/apotonick/cells), [Trailblazer](https://github.com/apotonick/trailblazer) and soon Reform and Representable/Roar, too.