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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 441fd2d2712b2ea5b6a15076088de3a1617945f0683251addd7e0be5f5077b9e
4
- data.tar.gz: 3d7cf921207b9000a838197669af05d619aadc1252b420d48d74771266dfbccf
3
+ metadata.gz: 41f5f9c69cd88716d3d05c109a89f1988eecd25e581de70af22e4c5f349800bd
4
+ data.tar.gz: a3f42179b0ac6eedf9bfe014bad4b24d91aa053b3e78d87927c0e1865031835b
5
5
  SHA512:
6
- metadata.gz: 447a280a18b005007788861863dce8b2dc647100add773615a1f5e2ae1a1151020f3955b0486da070a8995e32b7c9b168f5da5adf652b8fb8cb535e1e6b1b151
7
- data.tar.gz: 7514d83dd424338c51254855275b4031d45ba34a4814104130a2549aad7e0676327e288edfb1422b08a899d0528ffc48a93f8822a574f17d6af346a749ab57a3
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- keka (0.2.0)
4
+ keka (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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.ok
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.err(matched[:msg])
36
+ Keka.err_result(matched[:msg])
37
37
  end
38
38
 
39
39
  private
data/lib/keka/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Keka
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
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(err(msg)) if (evaluator.respond_to?(:ok?) ? evaluator.ok? : evaluator)
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(err(msg)) unless evaluator
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(ok(msg)) if evaluator
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 ok(msg = nil)
43
+ def ok_result(msg = nil)
36
44
  Result.new(true, msg)
37
45
  end
38
46
 
39
47
  # private (maybe)
40
- def err(msg = nil)
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.2.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-02-22 00:00:00.000000000 Z
11
+ date: 2020-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler