uber 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/README.md +19 -0
- data/lib/uber/builder.rb +2 -2
- data/lib/uber/uber_version.rb +1 -1
- data/test/builder_test.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ba4151c41861ad82f7e78103bd2c45b6cb0fc6e
|
4
|
+
data.tar.gz: ef674c49120eb7f86930e11ab8a12ac5bb3192e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78ff679013edac4b297e88352768e69d0daa56fc02d8491bd3fc6fb463c7336f3f8ef95fc9c667ba1c8a22af1f2b8c4b8b55821e4306d2558b858550eca89058
|
7
|
+
data.tar.gz: 2a3c2906155aa3c85ada42ba320040a19ad7165be9b695ad98e672c200a8e82b13b30fb4d3a8f91f4fef3ffd0817c0057c847ed5336b5324040411489f41eda9
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -197,6 +197,10 @@ Note how `#title` calls the original title and then downcases the string.
|
|
197
197
|
When included, `Builder` allows to add builder instructions on the class level. These can then be evaluated when instantiating
|
198
198
|
the class to conditionally build (sub-)classes based on the incoming parameters.
|
199
199
|
|
200
|
+
Builders can be defined in two different ways.
|
201
|
+
|
202
|
+
## Block Syntax
|
203
|
+
|
200
204
|
```ruby
|
201
205
|
class Listener
|
202
206
|
include Uber::Builder
|
@@ -228,6 +232,21 @@ Listener.build({}) #=> Listener
|
|
228
232
|
Listener.build({current_user: @current_user}) #=> SignedIn
|
229
233
|
```
|
230
234
|
|
235
|
+
## Proc Syntax
|
236
|
+
|
237
|
+
Setting up builders using the proc syntax allows to call `return` in the block. This is our preferred way to define builders.
|
238
|
+
|
239
|
+
```ruby
|
240
|
+
build ->(params) do
|
241
|
+
return SignedIn if params[:current_user]
|
242
|
+
return Admin if params[:admin]
|
243
|
+
Default
|
244
|
+
end
|
245
|
+
```
|
246
|
+
|
247
|
+
This makes the block extremely readable.
|
248
|
+
|
249
|
+
|
231
250
|
Note that builders are _not_ inherited to subclasses. This allows instantiating subclasses directly without running builders.
|
232
251
|
|
233
252
|
This pattern is used in [Cells](https://github.com/apotonick/cells), [Trailblazer](https://github.com/apotonick/trailblazer) and soon Reform and Representable/Roar, too.
|
data/lib/uber/builder.rb
CHANGED
data/lib/uber/uber_version.rb
CHANGED
data/test/builder_test.rb
CHANGED
@@ -56,4 +56,20 @@ class BuilderTest < MiniTest::Spec
|
|
56
56
|
it { Play.build({}).must_be_instance_of Play }
|
57
57
|
it { Play.build({evergreen: true}).must_be_instance_of Play }
|
58
58
|
it { Play.build({hit: true}).must_be_instance_of Play }
|
59
|
+
|
60
|
+
# test return from builds
|
61
|
+
class Boomerang
|
62
|
+
include Uber::Builder
|
63
|
+
|
64
|
+
builds ->(options) do
|
65
|
+
return Song if options[:hit]
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.build(options)
|
69
|
+
class_builder.call(options).new
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it { Boomerang.build({}).must_be_instance_of Boomerang }
|
74
|
+
it { Boomerang.build({hit: true}).must_be_instance_of Song }
|
59
75
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|