Class: RSpec::Rewind::RetryBudget
- Inherits:
-
Object
- Object
- RSpec::Rewind::RetryBudget
- Defined in:
- lib/rspec/rewind/retry_budget.rb
Instance Attribute Summary collapse
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#used ⇒ Object
readonly
Returns the value of attribute used.
Instance Method Summary collapse
- #consume ⇒ Object
- #consume! ⇒ Object
-
#initialize(limit) ⇒ RetryBudget
constructor
A new instance of RetryBudget.
- #remaining ⇒ Object
- #reset! ⇒ Object
- #unlimited? ⇒ Boolean
Constructor Details
#initialize(limit) ⇒ RetryBudget
Returns a new instance of RetryBudget.
22 23 24 25 26 |
# File 'lib/rspec/rewind/retry_budget.rb', line 22 def initialize(limit) @limit = normalize_limit(limit) @used = 0 @mutex = Mutex.new end |
Instance Attribute Details
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
20 21 22 |
# File 'lib/rspec/rewind/retry_budget.rb', line 20 def limit @limit end |
#used ⇒ Object (readonly)
Returns the value of attribute used.
20 21 22 |
# File 'lib/rspec/rewind/retry_budget.rb', line 20 def used @used end |
Instance Method Details
#consume ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rspec/rewind/retry_budget.rb', line 32 def consume return decision(true) if unlimited? @mutex.synchronize do return decision(false) if @used >= @limit @used += 1 decision(true) end end |
#consume! ⇒ Object
28 29 30 |
# File 'lib/rspec/rewind/retry_budget.rb', line 28 def consume! consume.allowed? end |
#remaining ⇒ Object
43 44 45 46 47 |
# File 'lib/rspec/rewind/retry_budget.rb', line 43 def remaining return Float::INFINITY if unlimited? [@limit - @used, 0].max end |
#reset! ⇒ Object
53 54 55 |
# File 'lib/rspec/rewind/retry_budget.rb', line 53 def reset! @mutex.synchronize { @used = 0 } end |
#unlimited? ⇒ Boolean
49 50 51 |
# File 'lib/rspec/rewind/retry_budget.rb', line 49 def unlimited? @limit.nil? end |