ehandl 0.0.0 → 0.0.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 +4 -4
- data/lib/ehandl.rb +10 -11
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2681ac82230deb5b51bc1475be197e41c5b220ae
|
|
4
|
+
data.tar.gz: b8fca7e30e728426095b3b9c415066e521b37311
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '04285f06f72539cb7ef9fce18e6afc1f0a350708288b0db7b4e0409b7a50ce2069f85960049c45fdb5c9853969fc431ffd0b1932be234298beb89ad7943f7fc3'
|
|
7
|
+
data.tar.gz: bc4f5523eb8a3032699b1ebc63fd5bcb23fa9a9b3add9e2bb4f4bca49c21c6d1dd314d722b321c4f44d66fb29d1021190e4020578752af7c0e3120a475356818
|
data/lib/ehandl.rb
CHANGED
|
@@ -31,32 +31,31 @@ module EHandl
|
|
|
31
31
|
|
|
32
32
|
def initialize(expr)
|
|
33
33
|
begin
|
|
34
|
-
result = expr.call
|
|
35
|
-
yield(Success.new(result))
|
|
34
|
+
@result = expr.call
|
|
35
|
+
yield(Success.new(@result))
|
|
36
36
|
rescue Exception => ex
|
|
37
37
|
@result = ex
|
|
38
|
-
yield(Failure.new(
|
|
38
|
+
yield(Failure.new(@result))
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
class ExceptionHandling
|
|
44
|
-
|
|
45
|
-
def initialize handlers, default
|
|
46
|
-
@ret = nil
|
|
44
|
+
def initialize handlers, default_handler
|
|
47
45
|
begin
|
|
48
|
-
@
|
|
46
|
+
@value = yield()
|
|
49
47
|
rescue Exception => ex
|
|
48
|
+
@value = ex
|
|
50
49
|
if(handlers[ex.class].nil?)
|
|
51
|
-
|
|
50
|
+
default_handler.call(ex)
|
|
52
51
|
else
|
|
53
52
|
handlers[ex.class].call(ex)
|
|
54
53
|
end
|
|
55
54
|
end
|
|
56
|
-
@
|
|
55
|
+
@value
|
|
57
56
|
end
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
|
|
58
|
+
attr_reader :value
|
|
60
59
|
end
|
|
61
60
|
|
|
62
61
|
def ehandl_included?
|