Class: Cabin::Metrics::Counter
- Inherits:
-
Object
- Object
- Cabin::Metrics::Counter
- Includes:
- Cabin::Metric
- Defined in:
- lib/cabin/metrics/counter.rb
Instance Method Summary collapse
-
#decr ⇒ Object
decrement this counter.
-
#incr ⇒ Object
increment this counter.
-
#initialize ⇒ Counter
constructor
A new instance of Counter.
- #to_hash ⇒ Object
- #value ⇒ Object
Methods included from Cabin::Metric
Methods included from Publisher
Methods included from Inspectable
Constructor Details
#initialize ⇒ Counter
Returns a new instance of Counter.
12 13 14 15 16 |
# File 'lib/cabin/metrics/counter.rb', line 12 def initialize @inspectables = [ :@value ] @value = 0 @lock = Mutex.new end |
Instance Method Details
#decr ⇒ Object
decrement this counter
25 26 27 28 |
# File 'lib/cabin/metrics/counter.rb', line 25 def decr @lock.synchronize { @value -= 1 } emit end |
#incr ⇒ Object
increment this counter
19 20 21 22 |
# File 'lib/cabin/metrics/counter.rb', line 19 def incr @lock.synchronize { @value += 1 } emit end |
#to_hash ⇒ Object
37 38 39 40 41 |
# File 'lib/cabin/metrics/counter.rb', line 37 def to_hash return @lock.synchronize do { :value => @value } end end |
#value ⇒ Object
32 33 34 |
# File 'lib/cabin/metrics/counter.rb', line 32 def value return @lock.synchronize { @value } end |