ehandl 0.0.0

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/ehandl.rb +65 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b4c2f525d714f8ff5cacc31380e76a4cac08fdb9
4
+ data.tar.gz: 5710be700fc93cebc3355f1815161869df98b096
5
+ SHA512:
6
+ metadata.gz: 46bb6f004c3f148f53c1ef855862ad73a3db734239e210554a0eecaad321cf9761f76ba1fd65664e9546eaf4e6d8a83613b757f5c93dc7b12df5a3e83e79bb5e
7
+ data.tar.gz: 874cc8a5e364f29d361fe76c16d5cdf4a111624e2f4c275eb814beb3a39e327c8f05011b3a0433787a11d7e9ba890cb6e26a59dcdd39f8c6a4be0dfaec914031
data/lib/ehandl.rb ADDED
@@ -0,0 +1,65 @@
1
+ module EHandl
2
+
3
+ class ResultCase
4
+ class Result
5
+ def initialize
6
+ raise 'This should not be instanciated.'
7
+ end
8
+
9
+ def method_missing(name, *args, &block) end
10
+ end
11
+
12
+ class Success < Result
13
+ def initialize(result)
14
+ @value = result
15
+ end
16
+
17
+ def success &proc
18
+ proc.call(@value)
19
+ end
20
+ end
21
+
22
+ class Failure < Result
23
+ def initialize(err)
24
+ @value = err
25
+ end
26
+
27
+ def failure &proc
28
+ proc.call(@value)
29
+ end
30
+ end
31
+
32
+ def initialize(expr)
33
+ begin
34
+ result = expr.call
35
+ yield(Success.new(result))
36
+ rescue Exception => ex
37
+ @result = ex
38
+ yield(Failure.new(ex))
39
+ end
40
+ end
41
+ end
42
+
43
+ class ExceptionHandling
44
+
45
+ def initialize handlers, default
46
+ @ret = nil
47
+ begin
48
+ @ret = yield()
49
+ rescue Exception => ex
50
+ if(handlers[ex.class].nil?)
51
+ default.call(ex)
52
+ else
53
+ handlers[ex.class].call(ex)
54
+ end
55
+ end
56
+ @ret
57
+ end
58
+
59
+
60
+ end
61
+
62
+ def ehandl_included?
63
+ true
64
+ end
65
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ehandl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Christian Angelone
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: a gem for handling exceptions
14
+ email: christiangelone@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/ehandl.rb
20
+ homepage: http://rubygems.org/gems/ehandl
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.6.11
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: EHandl
44
+ test_files: []