hallmonitor 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42d53cff1626075b9bc669c136a0bf7983f5880a
4
- data.tar.gz: bd47a1799c522220ea030ecadaa2af429cea63ca
3
+ metadata.gz: 2d62d082477737cb28427f17c204445f84782d1f
4
+ data.tar.gz: 949e08d6e519ecbe58cebd50f5b663671e0496ce
5
5
  SHA512:
6
- metadata.gz: 6a3b4472a87957f81d4fde0c5690a29d1e833b3565c1fd491d5fd121ac93e97d8276ca13b4a37dd634fd70d16cadf1a6e119bba9174bbd0e996591fc3231c6d5
7
- data.tar.gz: b80bd2b03fe7879ad46230194c08885d78d972e0d065ca2abc310aed0d8fecfbba34fb10654c8d7362de304afc61ca639fdf0835f035cc712dd3f546732d9425
6
+ metadata.gz: 6f244f06a3c98c8da024fb9b5e608a3a7cef717ac58092d88eb40b28827d1888286c386d31a48ecc4ef3f1c21e7aedcf6de4184f5f08cdabb11680426fd10e3d
7
+ data.tar.gz: d0c64796b5c0328f19dab64c63747375ee345b929b106592fc6bd4f27962906cab6cf1ee62c244b08b780e958dd134f795ee0068de234014f66a5e633df9092c
data/hallmonitor.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
 
24
24
  s.add_runtime_dependency("json", [">= 0"])
25
25
  s.add_runtime_dependency("statsd-ruby", [">= 0"])
26
- s.add_development_dependency("rspec", [">= 2.14"])
26
+ s.add_development_dependency("rspec", [">= 3.0"])
27
27
  s.add_development_dependency("rdoc", [">= 0"])
28
28
  s.add_development_dependency("bundler", ["~> 1.3"])
29
29
  s.add_development_dependency("pry-byebug", [">= 0"])
@@ -3,6 +3,12 @@
3
3
  module Hallmonitor
4
4
  module Monitored
5
5
  module ClassMethods
6
+ # Sets up a timer for a method by symbol. Method must have already been
7
+ # defined (ie. put this after the method definition)
8
+ # @param method_sym [Symbol] method name as a symbol
9
+ # @options [Hash] Optional settings:
10
+ # metric_name: [String] Metric name to emit, defaults to
11
+ # "#{underscore(name)}.#{method_sym}"
6
12
  def timer_for(method_sym, options = {})
7
13
  metric_name = options[:metric_name] || "#{underscore(name)}.#{method_sym}"
8
14
  send(:define_method, "#{method_sym}_with_hallmonitor_timer") do |*args|
@@ -15,6 +21,12 @@ module Hallmonitor
15
21
  alias_method method_sym, "#{method_sym}_with_hallmonitor_timer".to_sym
16
22
  end
17
23
 
24
+ # Sets up a counter for a method by symbol. Method must have already been
25
+ # defined (ie. put this after the method definition)
26
+ # @param method_sym [Symbol] method name as a symbol
27
+ # @options [Hash] Optional settings:
28
+ # metric_name: [String] Metric name to emit, defaults to
29
+ # "#{underscore(name)}.#{method_sym}"
18
30
  def count_for(method_sym, options = {})
19
31
  metric_name = options[:metric_name] || "#{underscore(name)}.#{method_sym}"
20
32
  send(:define_method, "#{method_sym}_with_hallmonitor_counter") do |*args|
@@ -36,38 +48,44 @@ module Hallmonitor
36
48
  word
37
49
  end
38
50
  end
39
-
51
+
40
52
  def self.included(base)
41
53
  base.extend(ClassMethods)
42
54
  end
43
-
44
- ##
55
+
45
56
  # Emits an event: either self or an event if one is passed in, or constructs
46
57
  # a base event from the passed in param
47
- # If the parameter is a #Hallmonitor::Event, it will be emitted as is.
48
- # Otherwise, a new Hallmonitor::Event will be created with the parameter and emitted.
58
+ # If the parameter is a {Hallmonitor::Event}, it will be emitted as is.
59
+ # Otherwise, a new {Hallmonitor::Event} will be created with the parameter
60
+ # and emitted.
61
+ # @param event [Mixed] The thing to emit, see method description
62
+ # @return nil
49
63
  def emit(event = nil)
50
- to_emit = self;
64
+ to_emit = self
51
65
  unless event.nil?
52
- to_emit = event.kind_of?(Hallmonitor::Event) ? event : Hallmonitor::Event.new(event)
66
+ to_emit = event.is_a?(Hallmonitor::Event) ? event : Hallmonitor::Event.new(event)
53
67
  end
54
-
68
+
55
69
  # If we were given a block, then we want to execute that
56
70
  yield(to_emit) if block_given?
57
-
71
+
58
72
  Outputter.output(to_emit)
73
+ nil
59
74
  end
60
75
 
61
- ##
62
76
  # Executes and times a block of code and emits a Hallmonitor::TimedEvent
77
+ # Will emit even if the block raises an error
78
+ # @param name [String] The name of the event to emit
79
+ # @return Whatever the block's return value is
63
80
  def watch(name)
64
81
  event = Hallmonitor::TimedEvent.new(name)
65
82
  event.start = Time.now
66
- retval = yield(event)
67
- event.stop = Time.now
68
- emit(event)
69
- retval
83
+ begin
84
+ yield(event)
85
+ ensure
86
+ event.stop = Time.now
87
+ emit(event)
88
+ end
70
89
  end
71
90
  end
72
91
  end
73
-
@@ -1,7 +1,7 @@
1
1
  module Hallmonitor
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 3
4
+ MINOR = 4
5
5
  PATCH = 0
6
6
  BUILD = nil
7
7
 
@@ -18,15 +18,15 @@ RSpec::Matchers.define :an_event_with_name do |expected_name|
18
18
  match { |actual| actual.is_a?(Hallmonitor::Event) && actual.name == expected_name }
19
19
  end
20
20
 
21
- RSpec::Matchers.define :a_timed_event_with_name do |expected_name|
21
+ RSpec::Matchers.define :a_timed_event_with_name do |expected_name|
22
22
  match { |actual| actual.is_a?(Hallmonitor::TimedEvent) && actual.name == expected_name }
23
23
  end
24
24
 
25
- describe Hallmonitor::Monitored do
25
+ RSpec.describe Hallmonitor::Monitored do
26
26
  subject { Thing.new }
27
27
 
28
28
  describe '#timer_for' do
29
- it 'should emit a timer with an appropriate name' do
29
+ it 'emits a timer with an appropriate name' do
30
30
  expect(Hallmonitor::Outputter).to(
31
31
  receive(:output).with(a_timed_event_with_name('thing.timer_for_test')))
32
32
  Thing.new.timer_for_test
@@ -34,7 +34,7 @@ describe Hallmonitor::Monitored do
34
34
  end
35
35
 
36
36
  describe '#count_for' do
37
- it 'should emit an event with an appropriate name' do
37
+ it 'emits an event with an appropriate name' do
38
38
  expect(Hallmonitor::Outputter).to(
39
39
  receive(:output).with(an_event_with_name('thing.count_for_test')))
40
40
  Thing.new.count_for_test
@@ -44,31 +44,53 @@ describe Hallmonitor::Monitored do
44
44
  describe '#watch' do
45
45
  let(:retval) { 'Hello World' }
46
46
  let(:name) { 'foo' }
47
- before do
48
- expect(Hallmonitor::Outputter).to receive(:output).with(a_timed_event_with_name(name))
49
- end
50
- it 'should return the value the block returns' do
47
+
48
+ it 'returns the value the block returns' do
51
49
  value = subject.watch(name) do
52
50
  retval
53
51
  end
54
52
  expect(value).to eq(retval)
53
+
54
+ value = subject.watch(name) do
55
+ nil
56
+ end
57
+ expect(value).to_not be
58
+ end
59
+
60
+ it 'emits a timer event for the block' do
61
+ expect(Hallmonitor::Outputter).to(
62
+ receive(:output).with(a_timed_event_with_name(name)))
63
+ subject.watch(name) do
64
+ 'foo'
65
+ end
66
+ end
67
+
68
+ describe 'when the block raises an error' do
69
+ it 'emits a timer for the block' do
70
+ expect(Hallmonitor::Outputter).to(
71
+ receive(:output).with(a_timed_event_with_name(name)))
72
+ expect {
73
+ subject.watch(name) do
74
+ raise 'OOPS!'
75
+ end
76
+ }.to raise_error
77
+ end
55
78
  end
56
79
  end
57
80
 
58
81
  describe '#emit' do
59
82
  describe 'with a string parameter' do
60
- let(:name) {"foo"}
61
- before do
62
- expect(Hallmonitor::Outputter).to receive(:output).with(an_event_with_name(name))
63
- end
83
+ let(:name) { 'foo' }
64
84
 
65
- it "should emit an event with the passed in name" do
85
+ it 'emits an event with the passed in name' do
86
+ expect(Hallmonitor::Outputter).to(
87
+ receive(:output).with(an_event_with_name(name)))
66
88
  subject.emit(name)
67
89
  end
68
90
  end
69
91
 
70
92
  describe 'with a block' do
71
- it 'should yield to the block' do
93
+ it 'yields to the block' do
72
94
  yielded = false
73
95
  var = nil
74
96
  subject.emit('foo') do |thing|
@@ -83,11 +105,9 @@ describe Hallmonitor::Monitored do
83
105
 
84
106
  describe 'with an event parameter' do
85
107
  let(:event) { Hallmonitor::Event.new('bar') }
86
- before do
87
- expect(Hallmonitor::Outputter).to receive(:output).with(event)
88
- end
89
108
 
90
- it 'should emit the passed in event' do
109
+ it 'emits the passed in event' do
110
+ expect(Hallmonitor::Outputter).to receive(:output).with(event)
91
111
  subject.emit(event)
92
112
  end
93
113
  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.3.0
4
+ version: 0.4.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: 2015-01-14 00:00:00.000000000 Z
11
+ date: 2015-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '2.14'
47
+ version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '2.14'
54
+ version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rdoc
57
57
  requirement: !ruby/object:Gem::Requirement