Class: Twingly::Metrics::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/twingly/metrics/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.



11
12
13
# File 'lib/twingly/metrics/counter.rb', line 11

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

Instance Method Details

#clearObject

Public: Reset the counter back to 0

Returns nothing.



18
19
20
# File 'lib/twingly/metrics/counter.rb', line 18

def clear
  @count.value = 0
end

#countObject

Public: The current count.

Returns the count.



43
44
45
# File 'lib/twingly/metrics/counter.rb', line 43

def count
  @count.value
end

#decrement(decr = 1) ⇒ Object

Public: Decrement the counter.

decr - The value to subtract from the counter.

Returns nothing.



36
37
38
# File 'lib/twingly/metrics/counter.rb', line 36

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.



27
28
29
# File 'lib/twingly/metrics/counter.rb', line 27

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