Class: Bundler::Retry

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/retry.rb

Overview

General purpose class for retrying code that may fail

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, exceptions = nil, retries = self.class.default_retries) ⇒ Retry

Returns a new instance of Retry.



19
20
21
22
23
24
# File 'lib/bundler/retry.rb', line 19

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_runObject

Returns the value of attribute current_run.



6
7
8
# File 'lib/bundler/retry.rb', line 6

def current_run
  @current_run
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/bundler/retry.rb', line 6

def name
  @name
end

#total_runsObject

Returns the value of attribute total_runs.



6
7
8
# File 'lib/bundler/retry.rb', line 6

def total_runs
  @total_runs
end

Class Method Details

.default_attemptsObject Also known as: attempts



9
10
11
# File 'lib/bundler/retry.rb', line 9

def default_attempts
  default_retries + 1
end

.default_retriesObject



14
15
16
# File 'lib/bundler/retry.rb', line 14

def default_retries
  Bundler.settings[:retry]
end

Instance Method Details

#attempt(&block) ⇒ Object Also known as: attempts



26
27
28
29
30
31
32
# File 'lib/bundler/retry.rb', line 26

def attempt(&block)
  @current_run = 0
  @failed      = false
  @error       = nil
  run(&block) while keep_trying?
  @result
end