formatted-metrics 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,10 +18,15 @@ module Metrics
18
18
  # Returns an Array of Metrics::Instrumenters that were written to STDOUT.
19
19
  def handle
20
20
  write instrumenters
21
+ result
21
22
  end
22
23
 
23
24
  private
24
25
 
26
+ def result
27
+ instrumenters.last.result
28
+ end
29
+
25
30
  def configuration
26
31
  Metrics.configuration
27
32
  end
@@ -38,6 +38,11 @@ module Metrics
38
38
  options[:source]
39
39
  end
40
40
 
41
+ def result
42
+ return nil unless block
43
+ @result ||= block.call
44
+ end
45
+
41
46
  private
42
47
  attr_reader :options, :block
43
48
 
@@ -48,7 +53,7 @@ module Metrics
48
53
  def time
49
54
  @time ||= begin
50
55
  start = Time.now
51
- block.call
56
+ result
52
57
  (Time.now - start) * 1000.0
53
58
  end
54
59
  end
@@ -1,3 +1,3 @@
1
1
  module FormattedMetrics
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.3'
3
3
  end
data/lib/metrics.rb CHANGED
@@ -40,8 +40,8 @@ module Metrics
40
40
  #
41
41
  # Example
42
42
  #
43
- # Metrics.group 'sidekiq' do
44
- # instrument 'request.time' do
43
+ # Metrics.group 'sidekiq' do |group|
44
+ # group.instrument 'request.time' do
45
45
  # begin
46
46
  # @app.call(env)
47
47
  # rescue Exception => e
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Metrics::Instrumenter do
4
- let(:instrumenter) { described_class.new('rack.request') { } }
4
+ let(:instrumenter) { described_class.new('rack.request') { 'foo' } }
5
5
 
6
6
  describe '.value' do
7
7
  subject { instrumenter.value }
@@ -42,4 +42,17 @@ describe Metrics::Instrumenter do
42
42
  it { should eq 'sidekiq' }
43
43
  end
44
44
  end
45
+
46
+ describe '.result' do
47
+ subject { instrumenter.result }
48
+
49
+ context 'with a block' do
50
+ it { should eq 'foo' }
51
+ end
52
+
53
+ context 'with a value' do
54
+ let(:instrumenter) { described_class.new('jobs.busy', 10, units: 'jobs') }
55
+ it { should be_nil }
56
+ end
57
+ end
45
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formatted-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-07 00:00:00.000000000 Z
12
+ date: 2013-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  segments:
108
108
  - 0
109
- hash: -3219838267565125949
109
+ hash: 4334694595459848801
110
110
  required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  none: false
112
112
  requirements:
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  segments:
117
117
  - 0
118
- hash: -3219838267565125949
118
+ hash: 4334694595459848801
119
119
  requirements: []
120
120
  rubyforge_project:
121
121
  rubygems_version: 1.8.23