Class: Bundler::Retry
- Inherits:
-
Object
- Object
- Bundler::Retry
- Defined in:
- lib/bundler/retry.rb
Overview
General purpose class for retrying code that may fail
Constant Summary collapse
- DEFAULT_ATTEMPTS =
2
Class Attribute Summary collapse
-
.attempts ⇒ Object
Returns the value of attribute attempts.
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.
Instance Method Summary collapse
- #attempt(&block) ⇒ Object (also: #attempts)
- #default_attempts ⇒ Object
-
#initialize(name, exceptions = nil, attempts = nil) ⇒ Retry
constructor
A new instance of Retry.
Constructor Details
#initialize(name, exceptions = nil, attempts = nil) ⇒ Retry
Returns a new instance of Retry.
11 12 13 14 15 16 |
# File 'lib/bundler/retry.rb', line 11 def initialize(name, exceptions = nil, attempts = nil) @name = name attempts ||= default_attempts @exceptions = Array(exceptions) || [] @total_runs = attempts.next # will run once, then upto attempts.times end |
Class Attribute Details
.attempts ⇒ Object
Returns the value of attribute attempts.
8 9 10 |
# File 'lib/bundler/retry.rb', line 8 def attempts @attempts end |
Instance Attribute Details
#current_run ⇒ Object
Returns the value of attribute current_run.
5 6 7 |
# File 'lib/bundler/retry.rb', line 5 def current_run @current_run end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/bundler/retry.rb', line 5 def name @name end |
#total_runs ⇒ Object
Returns the value of attribute total_runs.
5 6 7 |
# File 'lib/bundler/retry.rb', line 5 def total_runs @total_runs end |
Instance Method Details
#attempt(&block) ⇒ Object Also known as: attempts
23 24 25 26 27 28 29 30 31 |
# File 'lib/bundler/retry.rb', line 23 def attempt(&block) @current_run = 0 @failed = false @error = nil while do run(&block) end @result end |
#default_attempts ⇒ Object
18 19 20 21 |
# File 'lib/bundler/retry.rb', line 18 def default_attempts return Integer(self.class.attempts) if self.class.attempts DEFAULT_ATTEMPTS end |