Class: RSpec::Rewind::FileRetryBudget

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/rewind/retry_budget.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#limitObject (readonly)

Returns the value of attribute limit.



84
85
86
# File 'lib/rspec/rewind/retry_budget.rb', line 84

def limit
  @limit
end

#pathObject (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

#consumeObject



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

#remainingObject



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

Returns:

  • (Boolean)


113
114
115
# File 'lib/rspec/rewind/retry_budget.rb', line 113

def unlimited?
  false
end

#usedObject



105
106
107
# File 'lib/rspec/rewind/retry_budget.rb', line 105

def used
  with_locked_counter { |current| current }
end