Class: Ekylibre::FirstRun::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/ekylibre/first_run/counter.rb

Defined Under Namespace

Classes: CountExceeded

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(maximum = 0, &block) ⇒ Counter

Returns a new instance of Counter.


9
10
11
12
13
# File 'lib/ekylibre/first_run/counter.rb', line 9

def initialize(maximum = 0, &block)
  @count = 0
  @maximum = maximum
  @block = block if block_given?
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count


4
5
6
# File 'lib/ekylibre/first_run/counter.rb', line 4

def count
  @count
end

Instance Method Details

#check_point(increment = 1) ⇒ Object

Raises:


15
16
17
18
19
# File 'lib/ekylibre/first_run/counter.rb', line 15

def check_point(increment = 1)
  @count += increment
  @block.call(@count, increment) if @block
  raise CountExceeded if @maximum > 0 && @count >= @maximum
end