recoverable 0.0.4 → 0.0.5

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: 91d2cd9b2a88fc2cb068caa21ba39b4c6b2d7e15
4
- data.tar.gz: 2eadd39119ec415d732ccff3b822e3c95ff96da1
3
+ metadata.gz: e38db8978744c68969a3ffeaf3b1966bf0f50adb
4
+ data.tar.gz: a8d65bab14f3605a8a491bb40f768a9e93d76d5e
5
5
  SHA512:
6
- metadata.gz: b1fe4d4f02d158f7e0625d6282f382218b95d35e2ac753f8b7b802838bd5a68e1b023fed31934b28f762d10343ed399cdcd57d8ee6cb853aa022ee8d9f153aee
7
- data.tar.gz: af71452c0b87834ba674960dbf8dc08e7110b4cb76237973600a31aefc998337f3991d4282ff000d0a0b91df407f6228a515fa79bf9352bdcf3ae591de566745
6
+ metadata.gz: 8bd87b429c301c7d2d66b466bc49e455b99ffcf7b888ddb658df992830cd250c1634ff3d6de0afb8cfa11fc4f10fcd62012522c4004a380f4acc6a05a67c93cf
7
+ data.tar.gz: 5ac7b6bd0cb73e0a1d8f65bd34173f6ecd2d5d2391201a6dc6b2aabe14653b840e7a2eb69d947bb2ca06271207a0e4ebde785070f0b1156a4fb5913a48c314fe
data/README.md CHANGED
@@ -46,7 +46,7 @@ You can add recoverable to your class by simply extending the Gem and then telli
46
46
 
47
47
  end
48
48
  ```
49
- With the above configuration any instance of `Foo` will recover any `StandardError` on `#bar` and retry 2 times without a sleep between retries. After the second retry it will raise the error `Recoverable::RetryCountExceeded` along with the information about what error had occured.
49
+ With the above configuration any instance of `Foo` will recover any `StandardError` on `#bar` and retry 2 times without a wait between retries. After the second retry it will raise the error `Recoverable::RetryCountExceeded` along with the information about what error had occured.
50
50
 
51
51
  ### Configuration Options
52
52
 
@@ -76,14 +76,14 @@ Recoverable can rescue on a collection of errors as well, however these must be
76
76
  ```
77
77
  In the above case both `CustomError` and `OtherCustomError` will be rescued on the `#bar` method.
78
78
 
79
- #### Sleep
79
+ #### Wait
80
80
 
81
- Setting up your class with the following configuration will insert a 3 second sleep command between each retry:
81
+ Setting up your class with the following configuration will insert a 3 second wait(utilizing ruby Kernel#sleep) between each retry:
82
82
 
83
83
  ```ruby
84
84
  class Foo
85
85
  extend Recoverable
86
- recover :bar, tries: 2, sleep: 3
86
+ recover :bar, tries: 2, wait: 3
87
87
 
88
88
  def bar
89
89
  baz
@@ -92,9 +92,21 @@ Setting up your class with the following configuration will insert a 3 second sl
92
92
  end
93
93
  ```
94
94
 
95
+ You can override the implementation of wait at the configuration level by including a proc that takes an integer argument:
96
+ ```ruby
97
+ recover :bar, tries: 2, wait: 3, wait_method: Proc.new{ |int| "Another implementation utilizing wait time" }
98
+ ```
99
+
100
+ Additionally you can globally override the default wait implementation in an initializer by setting the default wait method:
101
+ ```ruby
102
+ Recoverable::Defaults.wait_method = Proc.new|int|
103
+ #Do something else with wait time here....
104
+ end
105
+ ```
106
+
95
107
  #### Custom Exception
96
108
 
97
- In addition to retrying, recoverable allows you to raise a custom exception after the rescue and retry attempts.
109
+ In addition to retrying, recoverable allows you to throw a custom exception after the rescue and retry attempts.
98
110
 
99
111
  ```ruby
100
112
 
@@ -102,7 +114,7 @@ In addition to retrying, recoverable allows you to raise a custom exception afte
102
114
 
103
115
  class Foo
104
116
  extend Recoverable
105
- recover :bar, tries: 2, custom_exception: MyException
117
+ recover :bar, tries: 2, throw: MyException
106
118
 
107
119
  def bar
108
120
  baz
@@ -135,6 +147,125 @@ Recoverable also allows you to configure a custom error handling method. This sh
135
147
  Please note that the name of the handler method should be passed to the configuration as a symbol. Also, the handler method can take either no arguments or a single keyword argument for `error:` if you would like access to the error inside the handler. Any other data inside the handler should be retrieved via instance methods or instance variables.
136
148
 
137
149
 
150
+ ### Inheritence
151
+
152
+ One of the more powerful aspects of the recoverable implementation is how it handles inheritence.
153
+
154
+ In the following example, recoverable is setup on the `#bar` method which is defined on both the parent and child class.
155
+
156
+ ```ruby
157
+ class ParentClass
158
+ extend Recoverable
159
+ recover :bar, tries: 2
160
+ def bar
161
+ baz
162
+ end
163
+
164
+ end
165
+
166
+ class ChildClass < ParentClass
167
+ def bar
168
+ super
169
+ end
170
+
171
+ def baz; end
172
+ end
173
+
174
+ ```
175
+
176
+ Now any call to bar that results in an error registered with the recoverable gem will be rescued and retried based on the configuration as long as the error occurs in the parent scope.
177
+
178
+ However in the following case the recoverable gem will rescue the error at the child level even though the error occurs in the parent class:
179
+
180
+ ```ruby
181
+ class ParentClass
182
+ def bar
183
+ baz
184
+ end
185
+
186
+ end
187
+
188
+ class ChildClass < ParentClass
189
+ extend Recoverable
190
+ recover :bar, tries: 2
191
+ def bar
192
+ super
193
+ end
194
+
195
+ def baz; end
196
+ end
197
+
198
+ ```
199
+
200
+ The gem will rescue down through multiple inheritence as well:
201
+
202
+ ```ruby
203
+ class ParentClass
204
+ extend Recoverable
205
+ recover :bar, tries: 2
206
+ def bar
207
+ baz
208
+ end
209
+
210
+ end
211
+
212
+ class ChildClass < ParentClass
213
+ def baz; end
214
+ end
215
+
216
+ class SubChildClass < ChildClass
217
+ def bar
218
+ super
219
+ end
220
+ end
221
+ ```
222
+ In the above, a call to the subchild class will throw an error that will be caught and retried by the recoverable configuration in the top level parent class
223
+
224
+ Lastly, error handler methods can be defined on either the parent or child class. For example, assuming that the method `bar` is called from a `ChildClass` instance, in the first example below the `handle_error` method will be called from the `ParentClass`
225
+
226
+ ```ruby
227
+ class ParentClass
228
+ extend Recoverable
229
+ recover :bar, tries: 2, custom_handler: :handle_error
230
+
231
+ def bar
232
+ baz
233
+ end
234
+
235
+ def handle_error(error:)
236
+ "Parent Handler!"
237
+ end
238
+ end
239
+
240
+ class ChildClass < ParentClass
241
+ def baz; end
242
+ end
243
+ ```
244
+ However, in the next example, the same configuration would call the `handle_error` method from the `ChildClass` instance.
245
+
246
+ ```ruby
247
+ class ParentClass
248
+ extend Recoverable
249
+ recover :bar, tries: 2, custom_handler: :handle_error
250
+
251
+ def bar
252
+ baz
253
+ end
254
+
255
+ def handle_error(error:)
256
+ "Parent Handler!"
257
+ end
258
+
259
+ end
260
+
261
+ class ChildClass < ParentClass
262
+ def baz; end
263
+
264
+ def handle_error(error:)
265
+ "Child Handler!"
266
+ end
267
+ end
268
+ ```
138
269
  ## How to contribute
139
270
 
140
271
  * Fork the project
@@ -1,3 +1,3 @@
1
1
  module Recoverable
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -390,7 +390,7 @@ RSpec.describe Recoverable do
390
390
  context 'Configuring recoverable on child class' do
391
391
  class self::TestParentClass
392
392
  def bar
393
- baz
393
+ qux
394
394
  end
395
395
  end
396
396
 
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recoverable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Jacobs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-13 00:00:00.000000000 Z
11
+ date: 2018-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: her
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '='
18
- - !ruby/object:Gem::Version
19
- version: 0.10.1
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '='
25
- - !ruby/object:Gem::Version
26
- version: 0.10.1
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: activesupport
29
15
  requirement: !ruby/object:Gem::Requirement