uber 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de21d3a8920ff5ceefd1ad8bf258cad849fe98fe
4
- data.tar.gz: ffa76af2fd9c3b8934fe8fe45ad42dfd905b7e5c
3
+ metadata.gz: 9ba4151c41861ad82f7e78103bd2c45b6cb0fc6e
4
+ data.tar.gz: ef674c49120eb7f86930e11ab8a12ac5bb3192e1
5
5
  SHA512:
6
- metadata.gz: ca76c101f1ab19441184b5635629c83aadd23ae7e75f9cf8e1f9b3aa9e6df58dcc961a80bf91f59ec12e44bb8c9384d2f583571133c7689eb44ace172ea0d86b
7
- data.tar.gz: 885a59c6f4f4ef7e686dbf6730c59e0ef85e4c01850cde97d45f3cd1f81fdebcb530d1df0e5877ed09e26ac17d5f70780009ba05672dab39c6d1541a2bedc6f0
6
+ metadata.gz: 78ff679013edac4b297e88352768e69d0daa56fc02d8491bd3fc6fb463c7336f3f8ef95fc9c667ba1c8a22af1f2b8c4b8b55821e4306d2558b858550eca89058
7
+ data.tar.gz: 2a3c2906155aa3c85ada42ba320040a19ad7165be9b695ad98e672c200a8e82b13b30fb4d3a8f91f4fef3ffd0817c0057c847ed5336b5324040411489f41eda9
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.0.13
2
+
3
+ * Add proc syntax for builders. This allows using `return` in the block. Thanks to @dutow for implementing this.
4
+
1
5
  # 0.0.12
2
6
 
3
7
  * Make it run with Ruby 2.2.
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.
@@ -79,8 +79,8 @@ module Uber
79
79
  # end
80
80
  #
81
81
  # In your view #cell will instantiate the right cell for you now.
82
- def builds(&block)
83
- builders << block
82
+ def builds(proc=nil, &block)
83
+ builders << (proc.kind_of?(Proc) ? proc : block)
84
84
  end
85
85
 
86
86
  def class_builder
@@ -1,3 +1,3 @@
1
1
  module Uber
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
@@ -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.12
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: 2014-12-25 00:00:00.000000000 Z
11
+ date: 2015-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake