class Chantier::FailurePolicies::Count

Simplest failure policy based on overall error count.

policy = FailAfterCount.new(4)
policy.limit_reached? # => false
1.times { policy.failure! }
policy.limit_reached? # => false
#... and then
4.times { policy.failure! }
policy.limit_reached? # => true

Public Class Methods

new(max_failures) click to toggle source
# File lib/failure_policies.rb, line 40
def initialize(max_failures)
  @max = max_failures
end

Public Instance Methods

arm!() click to toggle source

Arm the counter, prepare all the parameters

# File lib/failure_policies.rb, line 45
def arm!
  @count = 0
end
failure!() click to toggle source

Register a failure (simply increments the counter)

# File lib/failure_policies.rb, line 50
def failure!
  @count += 1
end
limit_reached?() click to toggle source

Tells whether we had too many failures

# File lib/failure_policies.rb, line 55
def limit_reached?
  @count >= @max
end