Class: Twingly::Metrics::Counter
- Inherits:
-
Object
- Object
- Twingly::Metrics::Counter
- 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
-
#clear ⇒ Object
Public: Reset the counter back to 0.
-
#count ⇒ Object
Public: The current count.
-
#decrement(decr = 1) ⇒ Object
Public: Decrement the counter.
-
#increment(incr = 1) ⇒ Object
Public: Increment the counter.
-
#initialize ⇒ Counter
constructor
Public: Initialize a new Counter.
Constructor Details
#initialize ⇒ Counter
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
#clear ⇒ Object
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 |
#count ⇒ Object
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 |