Module: Trusty::Errors::Retry
- Includes:
- ExceptionHandlers
- Defined in:
- lib/trusty/errors/retry.rb
Instance Method Summary collapse
-
#retry_block(options = {}, &block) ⇒ Object
retry a block of code.
-
#retry_method(method, options = {}) ⇒ Object
helper method to redefine method (a la alias_method_chain, etc).
Methods included from ExceptionHandlers
#notify_exception, #try_with_data
Instance Method Details
#retry_block(options = {}, &block) ⇒ Object
retry a block of code
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/trusty/errors/retry.rb', line 9 def retry_block( = {}, &block) = { :retry => 1, :data => {}, :type => StandardError }.merge() retries = case [:retry] when true 1 when Integer [:retry] else 0 end types = [ [:type] ].flatten.compact begin yield rescue *types => ex if retries > 0 return self.send(__method__, .merge(:retry => retries - 1), &block) else notify_exception(ex, :data => [:data], :raise => true) end end end |
#retry_method(method, options = {}) ⇒ Object
helper method to redefine method (a la alias_method_chain, etc)
39 40 41 42 43 44 45 46 |
# File 'lib/trusty/errors/retry.rb', line 39 def retry_method(method, = {}) define_method method do |*args, &block| super_method = method(:super) retry_block do super_method(*args, &block) end end end |