Class: Nunes::Adapters::Memory

Inherits:
Nunes::Adapter show all
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

#client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Nunes::Adapter

adapters, #prepare, wrap

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

Returns:

  • (Boolean)


8
9
10
# File 'lib/nunes/adapters/memory.rb', line 8

def self.wraps?(client)
  client.is_a?(Hash)
end

Instance Method Details

#clearObject

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.

Returns:

  • (Boolean)


51
52
53
# File 'lib/nunes/adapters/memory.rb', line 51

def counter?(metric)
  counters.detect { |op| op.first == metric }
end

#counter_metric_namesObject

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

#countersObject

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.

Returns:

  • (Boolean)


36
37
38
# File 'lib/nunes/adapters/memory.rb', line 36

def timer?(metric)
  timers.detect { |op| op.first == metric }
end

#timer_metric_namesObject

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

#timersObject

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