Class: RSpec::Rewind::FileRetryBudget
- Inherits:
-
Object
- Object
- RSpec::Rewind::FileRetryBudget
- Defined in:
- lib/rspec/rewind/retry_budget.rb
Instance Attribute Summary collapse
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #consume ⇒ Object
- #consume! ⇒ Object
-
#initialize(limit:, path:) ⇒ FileRetryBudget
constructor
A new instance of FileRetryBudget.
- #remaining ⇒ Object
- #reset! ⇒ Object
- #unlimited? ⇒ Boolean
- #used ⇒ Object
Constructor Details
#initialize(limit:, path:) ⇒ FileRetryBudget
Returns a new instance of FileRetryBudget.
86 87 88 89 |
# File 'lib/rspec/rewind/retry_budget.rb', line 86 def initialize(limit:, path:) @limit = normalize_limit(limit) @path = path end |
Instance Attribute Details
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
84 85 86 |
# File 'lib/rspec/rewind/retry_budget.rb', line 84 def limit @limit end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
84 85 86 |
# File 'lib/rspec/rewind/retry_budget.rb', line 84 def path @path end |
Instance Method Details
#consume ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/rspec/rewind/retry_budget.rb', line 95 def consume with_locked_counter do |used, file| return decision(false, used) if used >= @limit used += 1 write_used(file, used) decision(true, used) end end |
#consume! ⇒ Object
91 92 93 |
# File 'lib/rspec/rewind/retry_budget.rb', line 91 def consume! consume.allowed? end |
#remaining ⇒ Object
109 110 111 |
# File 'lib/rspec/rewind/retry_budget.rb', line 109 def remaining [@limit - used, 0].max end |
#reset! ⇒ Object
117 118 119 |
# File 'lib/rspec/rewind/retry_budget.rb', line 117 def reset! with_lock { |file| write_used(file, 0) } end |
#unlimited? ⇒ Boolean
113 114 115 |
# File 'lib/rspec/rewind/retry_budget.rb', line 113 def unlimited? false end |
#used ⇒ Object
105 106 107 |
# File 'lib/rspec/rewind/retry_budget.rb', line 105 def used with_locked_counter { |current| current } end |