lab42_result 0.1.3 → 0.1.4
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/README.md +6 -0
- data/lib/lab42/result.rb +3 -2
- data/lib/lab42/result/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afad1068206e801e09edb61a0e8331a6798437b90cb632295da197b4d7a36ee2
|
4
|
+
data.tar.gz: beefdd89db26b02c75fe60d9cf73168ffc23833910492a5c3b25e6a7e313bb8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd4490ae74ebe9f08f7b387651f095f942b44693284a01160a41ae1ada8330d1f72edcd8b0b02b17d5b3f5457814adeac44acc67f7f9c453cfcfef04258ef648
|
7
|
+
data.tar.gz: e5451d484d2d719daf38b843c2ae1e91207b2b58b21f4f07010079035d147b75be3f4783b14a21bd4437577c6898696319bae4e4d4cdf1e238fb146619f4c7f5
|
data/README.md
CHANGED
@@ -68,6 +68,12 @@ And as often times you will match on an error case only and raise a custom excep
|
|
68
68
|
expect{ error.raise!(KeyError) }.to raise_error(KeyError, "oh no!")
|
69
69
|
```
|
70
70
|
|
71
|
+
And also you might like to have access to the original message
|
72
|
+
```ruby
|
73
|
+
expect{ error.raise!(KeyError) { "key not found #{_1}"} }
|
74
|
+
.to raise_error(KeyError, "key not found oh no!")
|
75
|
+
```
|
76
|
+
|
71
77
|
#### Capturing Exceptions
|
72
78
|
|
73
79
|
If you have a piece of code like this:
|
data/lib/lab42/result.rb
CHANGED
@@ -10,9 +10,10 @@ module Lab42
|
|
10
10
|
status == :ok
|
11
11
|
end
|
12
12
|
|
13
|
-
def raise!(alternative_exception=nil)
|
13
|
+
def raise!(alternative_exception=nil, &blk)
|
14
14
|
return value if ok?
|
15
|
-
|
15
|
+
message = blk ? blk.(value) : value
|
16
|
+
raise((alternative_exception||status), message)
|
16
17
|
end
|
17
18
|
class << self
|
18
19
|
def new(*,**)
|
data/lib/lab42/result/version.rb
CHANGED