Class: Authify::API::Metrics
- Inherits:
-
Object
- Object
- Authify::API::Metrics
- Includes:
- Singleton
- Defined in:
- lib/authify/api/metrics.rb
Overview
A place to store metrics data
Instance Method Summary collapse
- #[](key) ⇒ Object
- #decrement(key, change = 1) ⇒ Object
- #each(&block) ⇒ Object
- #increment(key, change = 1) ⇒ Object
- #time(key) ⇒ Object
- #update(key, value) ⇒ Object
Instance Method Details
#[](key) ⇒ Object
19 20 21 |
# File 'lib/authify/api/metrics.rb', line 19 def [](key) storage[key] end |
#decrement(key, change = 1) ⇒ Object
15 16 17 |
# File 'lib/authify/api/metrics.rb', line 15 def decrement(key, change = 1) increment(key, -1 * change) end |
#each(&block) ⇒ Object
32 33 34 |
# File 'lib/authify/api/metrics.rb', line 32 def each(&block) storage.each(&block) end |
#increment(key, change = 1) ⇒ Object
11 12 13 |
# File 'lib/authify/api/metrics.rb', line 11 def increment(key, change = 1) storage.key?(key) ? storage[key] += change : storage[key] = change end |
#time(key) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/authify/api/metrics.rb', line 23 def time(key) timer = storage.key?(key) ? storage[key] : Hitimes::TimedMetric.new(key) result = timer.measure do yield end update(key, timer) result end |
#update(key, value) ⇒ Object
7 8 9 |
# File 'lib/authify/api/metrics.rb', line 7 def update(key, value) storage[key] = value end |