Class: Metriks::Counter

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

Overview

Public: Counters are one of the simplest metrics whose only operations are increment and decrement.

Instance Method Summary collapse

Constructor Details

#initializeCounter

Public: Initialize a new Counter.



8
9
10
# File 'lib/metriks/counter.rb', line 8

def initialize
  @count = Atomic.new(0)
end

Instance Method Details

#clearObject

Public: Reset the counter back to 0

Returns nothing.



15
16
17
# File 'lib/metriks/counter.rb', line 15

def clear
  @count.value = 0
end

#countObject

Public: The current count.

Returns the count.



40
41
42
# File 'lib/metriks/counter.rb', line 40

def count
  @count.value
end

#decrement(decr = 1) ⇒ Object

Public: Decrement the counter.

decr - The value to subtract from the counter.

Returns nothing.



33
34
35
# File 'lib/metriks/counter.rb', line 33

def decrement(decr = 1)
  @count.update { |v| v - decr }
end

#increment(incr = 1) ⇒ Object

Public: Increment the counter.

incr - The value to add to the counter.

Returns nothing.



24
25
26
# File 'lib/metriks/counter.rb', line 24

def increment(incr = 1)
  @count.update { |v| v + incr }
end