lib/attempt.rb in attempt-0.2.1 vs lib/attempt.rb in attempt-0.3.0
- old
+ new
@@ -4,24 +4,24 @@
# The Attempt class encapsulates methods related to multiple attempts at
# running the same method before actually failing.
class Attempt
# The version of the attempt library.
- VERSION = '0.2.1'
+ VERSION = '0.3.0'.freeze
# Warning raised if an attempt fails before the maximum number of tries
# has been reached.
- class Warning < StandardWarning; end
+ class Warning < StructuredWarnings::StandardWarning; end
- # Number of attempts to make before failing. The default is 3.
+ # Number of attempts to make before failing. The default is 3.
attr_accessor :tries
- # Number of seconds to wait between attempts. The default is 60.
+ # Number of seconds to wait between attempts. The default is 60.
attr_accessor :interval
# A boolean value that determines whether errors that would have been
- # raised should be sent to STDERR as warnings. The default is true.
+ # raised should be sent to STDERR as warnings. The default is true.
attr_accessor :warnings
# If you provide an IO handle to this option then errors that would
# have been raised are sent to that handle.
attr_accessor :log
@@ -48,14 +48,14 @@
@interval = 60 # Reasonable default
@log = nil # Should be an IO handle, if provided
@increment = nil # Should be an int, if provided
@timeout = nil # Wrap the code in a timeout block if provided
@level = Exception # Level of exception to be caught
- @warnings = true # Errors sent to STDERR as warnings if true
+ @warnings = true # Errors are sent to STDERR as warnings if true
yield self if block_given?
- end
+ end
# Attempt to perform the operation in the provided block up to +tries+
# times, sleeping +interval+ between each try.
#
# You will not typically use this method directly, but the Kernel#attempt
@@ -110,11 +110,11 @@
# attempt{ DBI.connect(dsn, user, passwd) }
#
def attempt(tries = 3, interval = 60, timeout = nil, &block)
raise 'no block given' unless block_given?
Attempt.new{ |a|
- a.tries = tries
- a.interval = interval
- a.timeout = timeout if timeout
+ a.tries = tries
+ a.interval = interval
+ a.timeout = timeout if timeout
}.attempt(&block)
end
end