Parent

Wait::BaseCounter

Attributes

attempt[R]
logger[RW]

Public Class Methods

new(total) click to toggle source
# File lib/counters/base.rb, line 6
def initialize(total)
  # Attempt to prevent causing an infinite loop by being very strict about
  # the value passed.
  unless total.is_a?(Fixnum) and total > 0
    raise(ArgumentError, "invalid number of attempts: #{total.inspect}")
  end

  @total = total
end

Public Instance Methods

increment() click to toggle source

Called before each attempt to increment the counter.

# File lib/counters/base.rb, line 22
def increment
  @attempt += 1
  log
end
last_attempt?() click to toggle source

Returns true if this is the last attempt.

# File lib/counters/base.rb, line 28
def last_attempt?
  @attempt == @total
end
log() click to toggle source

Logs the current attempt count.

# File lib/counters/base.rb, line 33
def log
  return if @logger.nil?

  @logger.debug("Counter") { "attempt #{self}" }
end
reset() click to toggle source

Called before all attempts to reset the counter.

# File lib/counters/base.rb, line 17
def reset
  @attempt = 0
end
to_s() click to toggle source

Returns a string representation of the current count.

# File lib/counters/base.rb, line 40
def to_s
  [@attempt, @total].join("/")
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.