hallmonitor 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hallmonitor/monitored.rb +19 -21
- data/lib/hallmonitor/version.rb +1 -1
- data/spec/monitored_spec.rb +45 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42d53cff1626075b9bc669c136a0bf7983f5880a
|
4
|
+
data.tar.gz: bd47a1799c522220ea030ecadaa2af429cea63ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a3b4472a87957f81d4fde0c5690a29d1e833b3565c1fd491d5fd121ac93e97d8276ca13b4a37dd634fd70d16cadf1a6e119bba9174bbd0e996591fc3231c6d5
|
7
|
+
data.tar.gz: b80bd2b03fe7879ad46230194c08885d78d972e0d065ca2abc310aed0d8fecfbba34fb10654c8d7362de304afc61ca639fdf0835f035cc712dd3f546732d9425
|
@@ -3,35 +3,35 @@
|
|
3
3
|
module Hallmonitor
|
4
4
|
module Monitored
|
5
5
|
module ClassMethods
|
6
|
-
def timer_for(method_sym, options={})
|
7
|
-
metric_name = options[:metric_name] || "#{
|
8
|
-
|
9
|
-
watch(metric_name) do
|
10
|
-
|
6
|
+
def timer_for(method_sym, options = {})
|
7
|
+
metric_name = options[:metric_name] || "#{underscore(name)}.#{method_sym}"
|
8
|
+
send(:define_method, "#{method_sym}_with_hallmonitor_timer") do |*args|
|
9
|
+
watch(metric_name) do
|
10
|
+
send("#{method_sym}_without_hallmonitor_timer".to_sym, *args)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
alias_method "#{method_sym
|
15
|
-
alias_method method_sym, "#{method_sym
|
14
|
+
alias_method "#{method_sym}_without_hallmonitor_timer".to_sym, method_sym
|
15
|
+
alias_method method_sym, "#{method_sym}_with_hallmonitor_timer".to_sym
|
16
16
|
end
|
17
17
|
|
18
|
-
def count_for(method_sym, options={})
|
19
|
-
metric_name = options[:metric_name] || "#{
|
20
|
-
|
18
|
+
def count_for(method_sym, options = {})
|
19
|
+
metric_name = options[:metric_name] || "#{underscore(name)}.#{method_sym}"
|
20
|
+
send(:define_method, "#{method_sym}_with_hallmonitor_counter") do |*args|
|
21
21
|
emit(metric_name)
|
22
|
-
|
22
|
+
send("#{method_sym}_without_hallmonitor_counter".to_sym, *args)
|
23
23
|
end
|
24
24
|
|
25
|
-
alias_method "#{method_sym
|
26
|
-
alias_method method_sym, "#{method_sym
|
25
|
+
alias_method "#{method_sym}_without_hallmonitor_counter".to_sym, method_sym
|
26
|
+
alias_method method_sym, "#{method_sym}_with_hallmonitor_counter".to_sym
|
27
27
|
end
|
28
28
|
|
29
29
|
def underscore(value)
|
30
30
|
word = value.dup
|
31
|
-
word.gsub!(/::/, '
|
32
|
-
word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
33
|
-
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
34
|
-
word.tr!(
|
31
|
+
word.gsub!(/::/, '.')
|
32
|
+
word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
33
|
+
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
34
|
+
word.tr!('-', ' ')
|
35
35
|
word.downcase!
|
36
36
|
word
|
37
37
|
end
|
@@ -48,14 +48,12 @@ module Hallmonitor
|
|
48
48
|
# Otherwise, a new Hallmonitor::Event will be created with the parameter and emitted.
|
49
49
|
def emit(event = nil)
|
50
50
|
to_emit = self;
|
51
|
-
|
51
|
+
unless event.nil?
|
52
52
|
to_emit = event.kind_of?(Hallmonitor::Event) ? event : Hallmonitor::Event.new(event)
|
53
53
|
end
|
54
54
|
|
55
55
|
# If we were given a block, then we want to execute that
|
56
|
-
if block_given?
|
57
|
-
yield(to_emit)
|
58
|
-
end
|
56
|
+
yield(to_emit) if block_given?
|
59
57
|
|
60
58
|
Outputter.output(to_emit)
|
61
59
|
end
|
data/lib/hallmonitor/version.rb
CHANGED
data/spec/monitored_spec.rb
CHANGED
@@ -2,22 +2,52 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
class Thing
|
4
4
|
include Hallmonitor::Monitored
|
5
|
+
|
6
|
+
def timer_for_test
|
7
|
+
# Nothing
|
8
|
+
end
|
9
|
+
timer_for :timer_for_test
|
10
|
+
|
11
|
+
def count_for_test
|
12
|
+
# Nothing
|
13
|
+
end
|
14
|
+
count_for :count_for_test
|
5
15
|
end
|
6
16
|
|
7
17
|
RSpec::Matchers.define :an_event_with_name do |expected_name|
|
8
|
-
match{ |actual| actual.name == expected_name}
|
18
|
+
match { |actual| actual.is_a?(Hallmonitor::Event) && actual.name == expected_name }
|
19
|
+
end
|
20
|
+
|
21
|
+
RSpec::Matchers.define :a_timed_event_with_name do |expected_name|
|
22
|
+
match { |actual| actual.is_a?(Hallmonitor::TimedEvent) && actual.name == expected_name }
|
9
23
|
end
|
10
24
|
|
11
25
|
describe Hallmonitor::Monitored do
|
12
|
-
subject {Thing.new}
|
26
|
+
subject { Thing.new }
|
27
|
+
|
28
|
+
describe '#timer_for' do
|
29
|
+
it 'should emit a timer with an appropriate name' do
|
30
|
+
expect(Hallmonitor::Outputter).to(
|
31
|
+
receive(:output).with(a_timed_event_with_name('thing.timer_for_test')))
|
32
|
+
Thing.new.timer_for_test
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#count_for' do
|
37
|
+
it 'should emit an event with an appropriate name' do
|
38
|
+
expect(Hallmonitor::Outputter).to(
|
39
|
+
receive(:output).with(an_event_with_name('thing.count_for_test')))
|
40
|
+
Thing.new.count_for_test
|
41
|
+
end
|
42
|
+
end
|
13
43
|
|
14
|
-
describe
|
15
|
-
let(:retval) {
|
16
|
-
let(:name) {
|
44
|
+
describe '#watch' do
|
45
|
+
let(:retval) { 'Hello World' }
|
46
|
+
let(:name) { 'foo' }
|
17
47
|
before do
|
18
|
-
expect(Hallmonitor::Outputter).to receive(:output).with(
|
48
|
+
expect(Hallmonitor::Outputter).to receive(:output).with(a_timed_event_with_name(name))
|
19
49
|
end
|
20
|
-
it
|
50
|
+
it 'should return the value the block returns' do
|
21
51
|
value = subject.watch(name) do
|
22
52
|
retval
|
23
53
|
end
|
@@ -25,8 +55,8 @@ describe Hallmonitor::Monitored do
|
|
25
55
|
end
|
26
56
|
end
|
27
57
|
|
28
|
-
describe
|
29
|
-
describe
|
58
|
+
describe '#emit' do
|
59
|
+
describe 'with a string parameter' do
|
30
60
|
let(:name) {"foo"}
|
31
61
|
before do
|
32
62
|
expect(Hallmonitor::Outputter).to receive(:output).with(an_event_with_name(name))
|
@@ -37,27 +67,27 @@ describe Hallmonitor::Monitored do
|
|
37
67
|
end
|
38
68
|
end
|
39
69
|
|
40
|
-
describe
|
41
|
-
it
|
70
|
+
describe 'with a block' do
|
71
|
+
it 'should yield to the block' do
|
42
72
|
yielded = false
|
43
73
|
var = nil
|
44
|
-
subject.emit(
|
74
|
+
subject.emit('foo') do |thing|
|
45
75
|
var = thing
|
46
76
|
yielded = true
|
47
77
|
end
|
48
78
|
expect(var).to_not be_nil
|
49
|
-
expect(var.name).to eq(
|
79
|
+
expect(var.name).to eq('foo')
|
50
80
|
expect(yielded).to be_truthy
|
51
81
|
end
|
52
82
|
end
|
53
83
|
|
54
84
|
describe 'with an event parameter' do
|
55
|
-
let(:event) {Hallmonitor::Event.new(
|
85
|
+
let(:event) { Hallmonitor::Event.new('bar') }
|
56
86
|
before do
|
57
87
|
expect(Hallmonitor::Outputter).to receive(:output).with(event)
|
58
88
|
end
|
59
89
|
|
60
|
-
it
|
90
|
+
it 'should emit the passed in event' do
|
61
91
|
subject.emit(event)
|
62
92
|
end
|
63
93
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hallmonitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris TenHarmsel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|