Class: CanvasStatsd::Counter
- Inherits:
-
Object
- Object
- CanvasStatsd::Counter
- Defined in:
- lib/canvas_statsd/counter.rb
Instance Attribute Summary collapse
-
#blocked_names ⇒ Object
readonly
Returns the value of attribute blocked_names.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Class Method Summary collapse
Instance Method Summary collapse
- #accepted_name?(name) ⇒ Boolean
- #count ⇒ Object
- #finalize_count(cookie) ⇒ Object
-
#initialize(key, blocked_names = []) ⇒ Counter
constructor
A new instance of Counter.
- #start ⇒ Object
- #track(name) ⇒ Object
Constructor Details
#initialize(key, blocked_names = []) ⇒ Counter
16 17 18 19 20 21 |
# File 'lib/canvas_statsd/counter.rb', line 16 def initialize(key, blocked_names=[]) @blocked_names = blocked_names @key = key @tls_key = "statsd.#{key}" self.class.register(self) end |
Instance Attribute Details
#blocked_names ⇒ Object (readonly)
Returns the value of attribute blocked_names.
14 15 16 |
# File 'lib/canvas_statsd/counter.rb', line 14 def blocked_names @blocked_names end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
13 14 15 |
# File 'lib/canvas_statsd/counter.rb', line 13 def key @key end |
Class Method Details
.counters ⇒ Object
4 5 6 |
# File 'lib/canvas_statsd/counter.rb', line 4 def counters @counters ||= {} end |
.register(counter) ⇒ Object
8 9 10 |
# File 'lib/canvas_statsd/counter.rb', line 8 def register(counter) counters[counter.key] = counter end |
Instance Method Details
#accepted_name?(name) ⇒ Boolean
39 40 41 |
# File 'lib/canvas_statsd/counter.rb', line 39 def accepted_name?(name) !blocked_names.include?(name) end |
#count ⇒ Object
35 36 37 |
# File 'lib/canvas_statsd/counter.rb', line 35 def count Thread.current[@tls_key] end |
#finalize_count(cookie) ⇒ Object
31 32 33 |
# File 'lib/canvas_statsd/counter.rb', line 31 def finalize_count() Thread.current[@tls_key] - end |
#start ⇒ Object
23 24 25 |
# File 'lib/canvas_statsd/counter.rb', line 23 def start Thread.current[@tls_key] ||= 0 end |
#track(name) ⇒ Object
27 28 29 |
# File 'lib/canvas_statsd/counter.rb', line 27 def track(name) Thread.current[@tls_key] += 1 if Thread.current[@tls_key] && accepted_name?(name) end |