lab42_result 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea0c3cc299098d0643da1e8f7a63521427d8b51db427b1aa5658955c3903687d
4
- data.tar.gz: 12cdbc32e1af1f8a0e0db6c34cf885b2ddb98ebca246b6171889b9537e4f6449
3
+ metadata.gz: 37f73fc3956392012ee23253db6a75ebca8af75a06375ff213a80e169fc1a515
4
+ data.tar.gz: 28949c288301cef5477c122ae97dd9d020b60f0a65d00513563f4b04fd96cf8b
5
5
  SHA512:
6
- metadata.gz: ca0ac0a4f545c949765a1f37d75b7b06eefd265c7c0d3ae625aba55581d0053a9761e47105af4f48480bc555444e32bd705a24b51056b795859ba90b1786cba7
7
- data.tar.gz: 7bc2d5db365415ba3276dfbbec4abb84ce0f1cfbd4037ee6ca55a502d95cbd8af1807903752750f5f05a2f1394aa89aa73da111e731d1004923cbada44276076
6
+ metadata.gz: 5a6827733845a78092efc9002136012671294dd385ba22c0bf39c239f923e491aaa06de80f06eeb1f77b9a9b26c5b06ff01d3d6941fa00a9c7c3f866c0663459
7
+ data.tar.gz: 5edf3309281f410ff35f2fee22652177d60b11b10619bbe999c007eb7a225a8127bd97992448a9f7037a4dbf9187e2ee5b6e9e9753165ceef3803b002676646b
data/README.md CHANGED
@@ -83,7 +83,7 @@ And its value cannot be accessed anymore
83
83
 
84
84
  But of course now we can call the error methods `#error` and `#exception`
85
85
  ```ruby
86
- expect(error.error).to eq("oh no")
86
+ expect(error.error).to eq("oh no!")
87
87
  expect(error.exception).to eq(RuntimeError)
88
88
 
89
89
  ```
@@ -252,7 +252,8 @@ As simple as that.
252
252
  Now Result allows for a seamingless integration with this pattern, first of all it
253
253
  exposes a module implementing it, but with a (more) reasonable name [Errors](lib/lab42/result/errors.rb)
254
254
 
255
- It will however have a slightly less lean interface as we are going to see
255
+ While this makes for a fatter interface, if well used, can make the workflow
256
+ in your class more elegant
256
257
 
257
258
  Given a class including Errors (pun intended)
258
259
  ```ruby
@@ -294,6 +295,17 @@ And eventually we get a helper to add many errors at once (always an optimist)
294
295
  expect(errors).to eq([:error3, :error4])
295
296
  ```
296
297
 
298
+ But I kept my favorite at the end (bad misstake, the audience is sleeping already)
299
+ ```ruby
300
+ great = MyErrors.new
301
+ output = []
302
+ great.if_ok { output << "I was completly fine" }
303
+ great.if_error { raise "Does not happen" }
304
+ great.add_errors("I got sick")
305
+ great.if_ok { raise "Still not happening" }
306
+ great.if_error { output << "But then, caught something" }
307
+ expect(output).to eq(["I was completly fine" , "But then, caught something"])
308
+ ```
297
309
 
298
310
  ## Even more detailed speculations
299
311
 
@@ -9,6 +9,14 @@ module Lab42
9
9
  @__errors__ ||= []
10
10
  end
11
11
 
12
+ def if_error(&blk)
13
+ ok? || blk.(self)
14
+ end
15
+
16
+ def if_ok(&blk)
17
+ ok? && blk.(self)
18
+ end
19
+
12
20
  def ok? = errors.empty?
13
21
 
14
22
  def to_result(value = self, exception: nil)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Lab42
4
4
  class Result
5
- VERSION = "0.2.0"
5
+ VERSION = "0.2.1"
6
6
  end
7
7
  end
8
8
  # SPDX-License-Identifier: AGPL-3.0-or-later
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lab42_result
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-15 00:00:00.000000000 Z
10
+ date: 2025-01-19 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: pry