Class: Counters::Memory
Instance Attribute Summary collapse
-
#hits ⇒ Object
readonly
Returns the value of attribute hits.
-
#latencies ⇒ Object
readonly
Returns the value of attribute latencies.
-
#magnitudes ⇒ Object
readonly
Returns the value of attribute magnitudes.
-
#pings ⇒ Object
readonly
Returns the value of attribute pings.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Memory
constructor
A new instance of Memory.
- #record_hit(key) ⇒ Object
- #record_latency(key, time_in_seconds) ⇒ Object
- #record_magnitude(key, value) ⇒ Object
- #record_ping(key) ⇒ Object
Methods inherited from Base
#hit, #latency, #magnitude, #ping
Constructor Details
#initialize(options = {}) ⇒ Memory
Returns a new instance of Memory.
7 8 9 10 11 12 13 14 |
# File 'lib/counters/memory.rb', line 7 def initialize(={}) super() @hits = Hash.new {|h,k| h[k] = 0} @magnitudes = Hash.new {|h,k| h[k] = 0} @latencies = Hash.new {|h,k| h[k] = Array.new} @pings = Hash.new end |
Instance Attribute Details
#hits ⇒ Object (readonly)
Returns the value of attribute hits.
5 6 7 |
# File 'lib/counters/memory.rb', line 5 def hits @hits end |
#latencies ⇒ Object (readonly)
Returns the value of attribute latencies.
5 6 7 |
# File 'lib/counters/memory.rb', line 5 def latencies @latencies end |
#magnitudes ⇒ Object (readonly)
Returns the value of attribute magnitudes.
5 6 7 |
# File 'lib/counters/memory.rb', line 5 def magnitudes @magnitudes end |
#pings ⇒ Object (readonly)
Returns the value of attribute pings.
5 6 7 |
# File 'lib/counters/memory.rb', line 5 def pings @pings end |
Instance Method Details
#record_hit(key) ⇒ Object
16 17 18 |
# File 'lib/counters/memory.rb', line 16 def record_hit(key) @hits[key] += 1 end |
#record_latency(key, time_in_seconds) ⇒ Object
24 25 26 |
# File 'lib/counters/memory.rb', line 24 def record_latency(key, time_in_seconds) @latencies[key] << time_in_seconds end |
#record_magnitude(key, value) ⇒ Object
28 29 30 |
# File 'lib/counters/memory.rb', line 28 def record_magnitude(key, value) @magnitudes[key] = value end |
#record_ping(key) ⇒ Object
20 21 22 |
# File 'lib/counters/memory.rb', line 20 def record_ping(key) @pings[key] = Time.now.utc end |