Class: Nunes::Adapters::Memory
- Inherits:
-
Nunes::Adapter
- Object
- Nunes::Adapter
- Nunes::Adapters::Memory
- Defined in:
- lib/nunes/adapters/memory.rb
Overview
Internal: Memory backend for recording instrumentation calls. This should never need to be used directly by a user of the gem.
Constant Summary
Constants inherited from Nunes::Adapter
Nunes::Adapter::Nothing, Nunes::Adapter::ReplaceRegex, Nunes::Adapter::Separator
Instance Attribute Summary
Attributes inherited from Nunes::Adapter
Class Method Summary collapse
Instance Method Summary collapse
-
#clear ⇒ Object
Internal: Empties the known counters and metrics.
-
#counter?(metric) ⇒ Boolean
Internal: Returns true/false if metric has been recorded as a counter.
-
#counter_metric_names ⇒ Object
Internal: Returns Array of only recorded counters.
-
#counters ⇒ Object
Internal: Returns Array of any recorded counters with values.
- #increment(metric, value = 1) ⇒ Object
-
#initialize(client = nil) ⇒ Memory
constructor
A new instance of Memory.
-
#timer?(metric) ⇒ Boolean
Internal: Returns true/false if metric has been recorded as a timer.
-
#timer_metric_names ⇒ Object
Internal: Returns Array of only recorded timers.
-
#timers ⇒ Object
Internal: Returns Array of any recorded timers with durations.
- #timing(metric, value) ⇒ Object
Methods inherited from Nunes::Adapter
Constructor Details
#initialize(client = nil) ⇒ Memory
Returns a new instance of Memory.
12 13 14 15 |
# File 'lib/nunes/adapters/memory.rb', line 12 def initialize(client = nil) @client = client || {} clear end |
Class Method Details
.wraps?(client) ⇒ Boolean
8 9 10 |
# File 'lib/nunes/adapters/memory.rb', line 8 def self.wraps?(client) client.is_a?(Hash) end |
Instance Method Details
#clear ⇒ Object
Internal: Empties the known counters and metrics.
Returns nothing.
58 59 60 61 62 63 |
# File 'lib/nunes/adapters/memory.rb', line 58 def clear @client ||= {} @client.clear @client[:timers] = [] @client[:counters] = [] end |
#counter?(metric) ⇒ Boolean
Internal: Returns true/false if metric has been recorded as a counter.
51 52 53 |
# File 'lib/nunes/adapters/memory.rb', line 51 def counter?(metric) counters.detect { |op| op.first == metric } end |
#counter_metric_names ⇒ Object
Internal: Returns Array of only recorded counters.
46 47 48 |
# File 'lib/nunes/adapters/memory.rb', line 46 def counter_metric_names counters.map { |op| op.first } end |
#counters ⇒ Object
Internal: Returns Array of any recorded counters with values.
41 42 43 |
# File 'lib/nunes/adapters/memory.rb', line 41 def counters @client.fetch(:counters) end |
#increment(metric, value = 1) ⇒ Object
17 18 19 |
# File 'lib/nunes/adapters/memory.rb', line 17 def increment(metric, value = 1) counters << [prepare(metric), value] end |
#timer?(metric) ⇒ Boolean
Internal: Returns true/false if metric has been recorded as a timer.
36 37 38 |
# File 'lib/nunes/adapters/memory.rb', line 36 def timer?(metric) timers.detect { |op| op.first == metric } end |
#timer_metric_names ⇒ Object
Internal: Returns Array of only recorded timers.
31 32 33 |
# File 'lib/nunes/adapters/memory.rb', line 31 def timer_metric_names timers.map { |op| op.first } end |
#timers ⇒ Object
Internal: Returns Array of any recorded timers with durations.
26 27 28 |
# File 'lib/nunes/adapters/memory.rb', line 26 def timers @client.fetch(:timers) end |
#timing(metric, value) ⇒ Object
21 22 23 |
# File 'lib/nunes/adapters/memory.rb', line 21 def timing(metric, value) timers << [prepare(metric), value] end |