keka 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +16 -0
- data/lib/keka/context.rb +2 -2
- data/lib/keka/version.rb +1 -1
- data/lib/keka.rb +13 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41f5f9c69cd88716d3d05c109a89f1988eecd25e581de70af22e4c5f349800bd
|
4
|
+
data.tar.gz: a3f42179b0ac6eedf9bfe014bad4b24d91aa053b3e78d87927c0e1865031835b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3093f3e717c8f27db52f71b3002e26a46de8051c51e04c558db2d39d2224bbcc9aa3ccce9da0ad0fc772e6285d3b8cf55a8e8e8b2fa52c7552eed08a2d149982
|
7
|
+
data.tar.gz: 3a74a02377cbda5a874634ff090ee93012750309fd455aa88f595b8b537178bd0d9aa72522899e0071a94832b7665731195d39090e232639c676bb43be3dffce
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## Version 0.3.0
|
6
|
+
* Support `.err!` and `.ok!` public methods.
|
7
|
+
* Rename `.ok` to `.ok_result`. [Breaking]
|
8
|
+
* Rename `.err` to `.err_result`. [Breaking]
|
9
|
+
|
5
10
|
## Version 0.2.0
|
6
11
|
* Support `.rescue_with` to handle exceptions in `.run` block.
|
7
12
|
* Add CI.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -57,6 +57,22 @@ end
|
|
57
57
|
Of course, you can also use `.err_unless!`, `.err_if!`, and `.ok_if!` outside
|
58
58
|
of the `Keka.run` block.
|
59
59
|
|
60
|
+
### Abort Unconditionally
|
61
|
+
|
62
|
+
Sometimes you know you want to abort, but you also need to a few things before aborting, such as saving the error result to database, logging, or submitting a metric to your monitoring service. You can use `.err!` or `.ok!` methods to abort from the current `Keka.run` block. Both methods can be invoked with or without a message argument.
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
def refund
|
66
|
+
Keka.run do
|
67
|
+
processor_response = payment.refund
|
68
|
+
unless processor_response.success
|
69
|
+
payment.log_processor_errors(processor_response.errors)
|
70
|
+
Keka.err! processor_response.errors
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
60
76
|
### Handle Exceptions
|
61
77
|
|
62
78
|
Before version 0.2.0, handling exceptions in `.run` block is a bit tricky. You might do something like this
|
data/lib/keka/context.rb
CHANGED
@@ -28,12 +28,12 @@ module Keka
|
|
28
28
|
def run
|
29
29
|
raise 'Block required!' unless block_given?
|
30
30
|
yield
|
31
|
-
Keka.
|
31
|
+
Keka.ok_result
|
32
32
|
rescue Keka::Halt => e
|
33
33
|
e.result
|
34
34
|
rescue StandardError => e
|
35
35
|
raise unless matched = opts[:rescue_exceptions].detect { |setting| e.is_a?(setting[:klass]) }
|
36
|
-
Keka.
|
36
|
+
Keka.err_result(matched[:msg])
|
37
37
|
end
|
38
38
|
|
39
39
|
private
|
data/lib/keka/version.rb
CHANGED
data/lib/keka.rb
CHANGED
@@ -8,7 +8,7 @@ module Keka
|
|
8
8
|
include Context::Originable
|
9
9
|
|
10
10
|
def err_if!(evaluator, msg = nil)
|
11
|
-
raise Halt.new(
|
11
|
+
raise Halt.new(err_result(msg)) if (evaluator.respond_to?(:ok?) ? evaluator.ok? : evaluator)
|
12
12
|
end
|
13
13
|
|
14
14
|
def err_unless!(evaluator, msg = nil)
|
@@ -17,7 +17,7 @@ module Keka
|
|
17
17
|
evaluator.msg = msg if msg
|
18
18
|
raise Halt.new(evaluator)
|
19
19
|
else
|
20
|
-
raise Halt.new(
|
20
|
+
raise Halt.new(err_result(msg)) unless evaluator
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -27,17 +27,25 @@ module Keka
|
|
27
27
|
evaluator.msg = msg if msg
|
28
28
|
raise Halt.new(evaluator)
|
29
29
|
else
|
30
|
-
raise Halt.new(
|
30
|
+
raise Halt.new(ok_result(msg)) if evaluator
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
def err!(msg = nil)
|
35
|
+
raise Halt.new(err_result(msg))
|
36
|
+
end
|
37
|
+
|
38
|
+
def ok!(msg = nil)
|
39
|
+
raise Halt.new(ok_result(msg))
|
40
|
+
end
|
41
|
+
|
34
42
|
# private (maybe)
|
35
|
-
def
|
43
|
+
def ok_result(msg = nil)
|
36
44
|
Result.new(true, msg)
|
37
45
|
end
|
38
46
|
|
39
47
|
# private (maybe)
|
40
|
-
def
|
48
|
+
def err_result(msg = nil)
|
41
49
|
Result.new(false, msg)
|
42
50
|
end
|
43
51
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zino
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|