lab42_result 0.1.2 → 0.1.3

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: 6920980da6412b0edd1ff5e0d2c35066454f7cf1ab690901466755f7e3911678
4
- data.tar.gz: b8fc3146ae849c55af68408798c9af35e232222892188d42067605516704b61c
3
+ metadata.gz: 750477a65983be7bc572b456f0655833cc71fcd56a5ee0ec4ceb7a474611ea2b
4
+ data.tar.gz: 857690234b894bfc357c5dfddd167c8ad3f4f66096192e25bafe0a0d07488cf6
5
5
  SHA512:
6
- metadata.gz: 5f062d735291bbac1d4bb7f17b27c8f1cfb33c97753ae6e775cbf0d90b20836652e03f25572e4c82d3a9f0e1212cf0d8b3d946dea9dcbd6ae4df26ae5f5cb18c
7
- data.tar.gz: afdd6e1e1397ecb4c1e66f9813374aa2aa9e1333ceef4d03448bf930da7d47d8fb506d65990982650cbecf9d9db0157b9107f940b3c41573290ea7cb23e2ab0a
6
+ metadata.gz: 7c7c7a15c3f80d3ceebd8284aace83bea7cc6e622b9b7f05d0a6c6bef385440e28a3f6895ecc3a815a049a4949474479ef700285ab132ee6316546874aff4df0
7
+ data.tar.gz: e27d27f6b56da1ac24af9a70adc5a6b0e317f883a2fcd586113ba443014a26d1380dfb6325c462602de2f35301689668e9dea7ac11b9c8c9c13ada433798def0
data/README.md CHANGED
@@ -1,3 +1,6 @@
1
+
2
+ [![Gem Version](https://badge.fury.io/rb/lab42_result.svg)](http://badge.fury.io/rb/lab42_result)
3
+
1
4
  # Lab42::Result
2
5
 
3
6
  A result encapsulation class, like the `Either` type in Haskell.
@@ -36,6 +39,10 @@ Example: And will not raise any error
36
39
  expect( ok.raise! ).to eq(42)
37
40
  ```
38
41
 
42
+ And the same holds for `raise!` with a replacement Exception
43
+ ```ruby
44
+ expect( ok.raise!(ArgumentError) ).to eq(42)
45
+ ```
39
46
  #### If Error
40
47
 
41
48
  Example: It's h(error)
@@ -56,6 +63,11 @@ Example: And will certainly raise this time
56
63
  expect{ error.raise! }.to raise_error(RuntimeError, "oh no!")
57
64
  ```
58
65
 
66
+ And as often times you will match on an error case only and raise a custom exception the following shortcut comes in handy
67
+ ```ruby
68
+ expect{ error.raise!(KeyError) }.to raise_error(KeyError, "oh no!")
69
+ ```
70
+
59
71
  #### Capturing Exceptions
60
72
 
61
73
  If you have a piece of code like this:
@@ -10,9 +10,9 @@ module Lab42
10
10
  status == :ok
11
11
  end
12
12
 
13
- def raise!
13
+ def raise!(alternative_exception=nil)
14
14
  return value if ok?
15
- raise status, value
15
+ raise((alternative_exception||status), value)
16
16
  end
17
17
  class << self
18
18
  def new(*,**)
@@ -1,5 +1,5 @@
1
1
  module Lab42
2
2
  class Result
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lab42_result
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-15 00:00:00.000000000 Z
11
+ date: 2020-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry