Class: MethodDecorators::Retry
- Defined in:
- lib/method_decorators/retry.rb
Instance Method Summary collapse
- #call(orig, this, *args, &blk) ⇒ Object
-
#initialize(max, options = {}) ⇒ Retry
constructor
A new instance of Retry.
Methods inherited from Decorator
Constructor Details
#initialize(max, options = {}) ⇒ Retry
Returns a new instance of Retry.
5 6 7 8 9 |
# File 'lib/method_decorators/retry.rb', line 5 def initialize(max, = {}) @max = max = @exceptions = [:exceptions] || [StandardError] end |
Instance Method Details
#call(orig, this, *args, &blk) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/method_decorators/retry.rb', line 11 def call(orig, this, *args, &blk) attempts = 0 begin attempts += 1 orig.call(*args, &blk) rescue *@exceptions if attempts < @max sleep([:sleep]) if [:sleep] retry end raise end end |