Class: Counters::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/counters/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
8
9
10
11
|
# File 'lib/counters/base.rb', line 8
def initialize(options={})
@options = options
@namespace = options[:namespace]
end
|
Instance Attribute Details
#namespace(*args) ⇒ Object
40
41
42
43
44
45
46
47
48
|
# File 'lib/counters/base.rb', line 40
def namespace(*args)
if args.empty? then
@namespace
else
other = self.dup
other.namespace = [@namespace.to_s, args.first].join(".")
other
end
end
|
Instance Method Details
#hit(key) ⇒ Object
13
14
15
16
|
# File 'lib/counters/base.rb', line 13
def hit(key)
validate(key)
record_hit(namespaced_key(key))
end
|
#latency(key, time_in_seconds = nil) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/counters/base.rb', line 23
def latency(key, time_in_seconds=nil)
result = nil
validate(key)
if block_given? then
raise ArgumentError, "Must pass either a latency or a block, not both: received #{time_in_seconds.inspect} in addition to a block" if time_in_seconds
time_in_seconds = Benchmark.measure { result = yield }.real
end
record_latency(namespaced_key(key), time_in_seconds)
result
end
|
#magnitude(key, value) ⇒ Object
18
19
20
21
|
# File 'lib/counters/base.rb', line 18
def magnitude(key, value)
validate(key)
record_magnitude(namespaced_key(key), value)
end
|
#ping(key) ⇒ Object
35
36
37
38
|
# File 'lib/counters/base.rb', line 35
def ping(key)
validate(key)
record_ping(namespaced_key(key))
end
|