recoverable 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: 8dea1219bb101ee0ff89ca0794c8a4c2648275c0
4
- data.tar.gz: a82f71d6ade61164f07701c5c1bd26b375e235cb
3
+ metadata.gz: ef2d6b67667197eda7be6937a1852cd3479b8054
4
+ data.tar.gz: ba58fff01c7747b79285db1bcf1412470620c2a4
5
5
  SHA512:
6
- metadata.gz: a425e9704da44b71696b128c71f4ff4b42934433335a214befc5467d887fb28ffd32f4cdd7757311ed7264a79707ec5a1b12ac2270be2378e9c8f85f6e54205a
7
- data.tar.gz: affcc22857a7fffba3ddc96b326b9347429fd78e021ffca345ac99ca5b98f7bd69e393a443a282076b99b76503555746c14154d7f7831b58171da60eaed6b850
6
+ metadata.gz: a739f0dca356eb2bf9cb349b777be6aae48a4432399c9fd1ea3897e168dd1edb97ecdf8a6a662c36d85be388566857f51c1d5a0d3f6b403bad880655a2290115
7
+ data.tar.gz: acae59acb3450432c5abd0c5af29fc30c2f4852072f64798a3dcc17c99bfb033f66d4a524686c177f68f3c40ac3d84d3123f2188032183fdd1ee208b2144ec82
@@ -1,18 +1,19 @@
1
1
  module Recoverable
2
- def recover(method_name, times: 1, on: StandardError, sleep: nil, custom_handler: nil, custom_exception: RetryCountExceeded)
2
+ def recover(method_name, tries: 1, on: StandardError, sleep: nil, custom_handler: nil, custom_exception: RetryCountExceeded)
3
3
  recoverable = Array.wrap(on)
4
- proxy = create_proxy(method_name: method_name, times: times, recoverable: recoverable, sleep: sleep, custom_handler: custom_handler, custom_exception: custom_exception)
4
+ proxy = create_proxy(method_name: method_name, tries: tries, recoverable: recoverable, sleep: sleep, custom_handler: custom_handler, custom_exception: custom_exception)
5
5
  self.prepend proxy
6
6
  end
7
7
 
8
- def create_proxy(method_name:, times:, recoverable:, sleep:, custom_handler:, custom_exception:)
8
+ def create_proxy(method_name:, tries:, recoverable:, sleep:, custom_handler:, custom_exception:)
9
9
  Module.new do
10
10
  define_method(method_name) do |*args|
11
+ retries = tries
11
12
  begin
12
13
  super *args
13
14
  rescue *recoverable => error
14
15
  sleep(sleep) if sleep
15
- retry if (times -= 1) > 0
16
+ retry if (retries -= 1) > 0
16
17
  self.class.handle_exception(instance: self, custom_handler: custom_handler, args: args, error: error, custom_exception: custom_exception)
17
18
  end
18
19
  end
@@ -1,3 +1,3 @@
1
1
  module Recoverable
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -5,7 +5,7 @@ RSpec.describe Recoverable do
5
5
  context "passing no errors" do
6
6
  class self::TestClass
7
7
  extend Recoverable
8
- recover :bar, times: 2
8
+ recover :bar, tries: 2
9
9
 
10
10
  def bar; baz; end
11
11
  def baz; end
@@ -28,7 +28,7 @@ RSpec.describe Recoverable do
28
28
  context "passing specific errors" do
29
29
  class self::TestClass
30
30
  extend Recoverable
31
- recover :bar, times: 2, on: CustomError
31
+ recover :bar, tries: 2, on: CustomError
32
32
 
33
33
  def bar; baz; end
34
34
  def baz; end
@@ -55,7 +55,7 @@ RSpec.describe Recoverable do
55
55
  context "passing specific sleep" do
56
56
  class self::TestClass
57
57
  extend Recoverable
58
- recover :bar, times: 2, on: CustomError, sleep: 3
58
+ recover :bar, tries: 2, on: CustomError, sleep: 3
59
59
 
60
60
  def bar; baz; end
61
61
  def baz; end
@@ -72,7 +72,7 @@ RSpec.describe Recoverable do
72
72
  context "passing custom error handler" do
73
73
  class self::TestClass
74
74
  extend Recoverable
75
- recover :bar, times: 2, on: CustomError, custom_handler: :handle_error
75
+ recover :bar, tries: 2, on: CustomError, custom_handler: :handle_error
76
76
 
77
77
  def bar; baz; end
78
78
  def baz; end
@@ -92,7 +92,7 @@ RSpec.describe Recoverable do
92
92
  context "passing custom error handler with error message" do
93
93
  class self::TestClass
94
94
  extend Recoverable
95
- recover :bar, times: 2, on: CustomError, custom_handler: :handle_error
95
+ recover :bar, tries: 2, on: CustomError, custom_handler: :handle_error
96
96
 
97
97
  def bar(arg:nil)
98
98
  baz
@@ -118,7 +118,7 @@ RSpec.describe Recoverable do
118
118
  context "passing custom error handler with arg" do
119
119
  class self::TestClass
120
120
  extend Recoverable
121
- recover :bar, times: 2, on: CustomError, custom_handler: :handle_error
121
+ recover :bar, tries: 2, on: CustomError, custom_handler: :handle_error
122
122
 
123
123
  def bar(arg:nil)
124
124
  baz
@@ -144,7 +144,7 @@ RSpec.describe Recoverable do
144
144
  context "passing custom error handler with a method call" do
145
145
  class self::TestClass
146
146
  extend Recoverable
147
- recover :bar, times: 2, on: CustomError, custom_handler: :handle_error
147
+ recover :bar, tries: 2, on: CustomError, custom_handler: :handle_error
148
148
 
149
149
  def bar(arg:nil)
150
150
  baz
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recoverable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Jacobs