Class: Bundler::Retry
- Inherits:
-
Object
- Object
- Bundler::Retry
- Defined in:
- lib/bundler/retry.rb
Overview
General purpose class for retrying code that may fail
Instance Attribute Summary collapse
-
#current_run ⇒ Object
Returns the value of attribute current_run.
-
#name ⇒ Object
Returns the value of attribute name.
-
#total_runs ⇒ Object
Returns the value of attribute total_runs.
Class Method Summary collapse
- .default_attempts ⇒ Object (also: attempts)
- .default_retries ⇒ Object
Instance Method Summary collapse
- #attempt(&block) ⇒ Object (also: #attempts)
-
#initialize(name, exceptions = nil, retries = self.class.default_retries) ⇒ Retry
constructor
A new instance of Retry.
Constructor Details
#initialize(name, exceptions = nil, retries = self.class.default_retries) ⇒ Retry
Returns a new instance of Retry.
17 18 19 20 21 22 |
# File 'lib/bundler/retry.rb', line 17 def initialize(name, exceptions = nil, retries = self.class.default_retries) @name = name @retries = retries @exceptions = Array(exceptions) || [] @total_runs = @retries + 1 # will run once, then upto attempts.times end |
Instance Attribute Details
#current_run ⇒ Object
Returns the value of attribute current_run.
4 5 6 |
# File 'lib/bundler/retry.rb', line 4 def current_run @current_run end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/bundler/retry.rb', line 4 def name @name end |
#total_runs ⇒ Object
Returns the value of attribute total_runs.
4 5 6 |
# File 'lib/bundler/retry.rb', line 4 def total_runs @total_runs end |
Class Method Details
.default_attempts ⇒ Object Also known as: attempts
7 8 9 |
# File 'lib/bundler/retry.rb', line 7 def default_attempts default_retries + 1 end |
Instance Method Details
#attempt(&block) ⇒ Object Also known as: attempts
24 25 26 27 28 29 30 31 32 |
# File 'lib/bundler/retry.rb', line 24 def attempt(&block) @current_run = 0 @failed = false @error = nil while do run(&block) end @result end |