Class: Chantier::FailurePolicies::Count
- Defined in:
- lib/failure_policies.rb
Overview
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
Instance Method Summary collapse
-
#arm! ⇒ Object
Arm the counter, prepare all the parameters.
-
#failure! ⇒ Object
Register a failure (simply increments the counter).
-
#initialize(max_failures) ⇒ Count
constructor
A new instance of Count.
-
#limit_reached? ⇒ Boolean
Tells whether we had too many failures.
Methods inherited from None
Constructor Details
#initialize(max_failures) ⇒ Count
Returns a new instance of Count.
40 41 42 |
# File 'lib/failure_policies.rb', line 40 def initialize(max_failures) @max = max_failures end |
Instance Method Details
#arm! ⇒ Object
Arm the counter, prepare all the parameters
45 46 47 |
# File 'lib/failure_policies.rb', line 45 def arm! @count = 0 end |
#failure! ⇒ Object
Register a failure (simply increments the counter)
50 51 52 |
# File 'lib/failure_policies.rb', line 50 def failure! @count += 1 end |
#limit_reached? ⇒ Boolean
Tells whether we had too many failures
55 56 57 |
# File 'lib/failure_policies.rb', line 55 def limit_reached? @count >= @max end |