10
11
12
13
14
15
16
17
18
19
|
# File 'lib/curation_concerns/models/utils.rb', line 10
def retry_unless(number_of_tries, condition, &_block)
fail ArgumentError, 'First argument must be an enumerator' unless number_of_tries.is_a? Enumerator
fail ArgumentError, 'Second argument must be a lambda' unless condition.respond_to? :call
fail ArgumentError, 'Must pass a block of code to retry' unless block_given?
number_of_tries.each do
result = yield
return result unless condition.call
end
fail 'retry_unless could not complete successfully. Try upping the # of tries?'
end
|