pliny 0.20.0 → 0.20.1

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: 686ea485950159a4111ea7d2a0cf08d1a9945a57
4
- data.tar.gz: 600951ff54aabd3e2cc39094b305daed9b1fb284
3
+ metadata.gz: 1424dc0c288ffda2c41014a5be8021194146f328
4
+ data.tar.gz: 238fb1ae442b1392ebd61ffeea5c966501613c13
5
5
  SHA512:
6
- metadata.gz: 8f8964c9b05a857ae80961fba8551eaa8634f864faad1dc7f3305e73fbc4aeb63663e1ded6fbe7ac585042542a50d92cb7ec62b836037586d0413b17de7d512e
7
- data.tar.gz: 5cf995f52ea9273783ec42cc4f19cb57fa7e762a6ec24cab57ca98b5653f0fcdc404f83529bebde057e95d1040ff39a58ffe3aa07f22e45953fe8831b491201c
6
+ metadata.gz: 66625177b344dbf1074856e7ef2a220df87ace5142608e83898641b6831ae8f6c57f0b9e456317483a2b971331ce349c20e092cec2cafd94170dbe0edf1a9b48
7
+ data.tar.gz: 56eb5cd7378f88adc4750dea565ccb373ea4f9594cd25eac2eb9a3035c4538efdb3b1974239c864ac17049c71bce468a82c1764a68c8b7689e34167d6805ab1a
@@ -16,15 +16,27 @@ module Pliny
16
16
  counts
17
17
  end
18
18
 
19
- def measure(*names, &block)
20
- elapsed, return_value = time_elapsed(&block)
21
- measures = Hash[names.map { |n| ["#{Config.app_name}.#{n}", elapsed] }]
19
+ def measure(*names, **opts, &block)
20
+ if block
21
+ elapsed, return_value = time_elapsed(&block)
22
+ end
23
+
24
+ measurement =
25
+ if opts.has_key?(:value)
26
+ opts[:value]
27
+ elsif block
28
+ elapsed
29
+ else
30
+ 0
31
+ end
32
+
33
+ measures = Hash[names.map { |n| ["#{Config.app_name}.#{n}", measurement] }]
22
34
 
23
35
  backends.each do |backend|
24
36
  report_and_catch { backend.report_measures(measures) }
25
37
  end
26
38
 
27
- return_value
39
+ block ? return_value : measures
28
40
  end
29
41
 
30
42
  private
@@ -19,6 +19,8 @@ module Pliny
19
19
  [file.count("/"), file]
20
20
  end
21
21
 
22
+ raise LoadError, "empty glob path: #{path}" if files.empty?
23
+
22
24
  files.each do |file|
23
25
  require file
24
26
  end
@@ -1,3 +1,3 @@
1
1
  module Pliny
2
- VERSION = "0.20.0"
2
+ VERSION = "0.20.1"
3
3
  end
@@ -29,7 +29,7 @@ module Initializer
29
29
  end
30
30
 
31
31
  def self.require_initializers
32
- Pliny::Utils.require_glob("#{Config.root}/config/initializers/*.rb")
32
+ require!("config/initializers/*")
33
33
  end
34
34
 
35
35
  def self.require!(globs)
@@ -52,14 +52,14 @@ describe Pliny::Metrics do
52
52
  Pliny::Metrics.backends = [test_backend]
53
53
  end
54
54
 
55
- it "measures a single key" do
55
+ it "measures a block's execution time with a single key" do
56
56
  metrics.measure(:foo) { }
57
57
  expect(test_backend).to have_received(:report_measures).once.with(
58
58
  "pliny.foo" => 0
59
59
  )
60
60
  end
61
61
 
62
- it "measures a single key over a minute" do
62
+ it "measures a long block's execution time with a single key" do
63
63
  metrics.measure(:foo) do
64
64
  Timecop.travel(60)
65
65
  end
@@ -69,12 +69,34 @@ describe Pliny::Metrics do
69
69
  end
70
70
  end
71
71
 
72
- it "measures multiple keys" do
72
+ it "measures a block's execution time with multiple keys" do
73
73
  metrics.measure(:foo, :bar) { }
74
74
  expect(test_backend).to have_received(:report_measures).once.with(
75
75
  "pliny.foo" => 0,
76
76
  "pliny.bar" => 0
77
77
  )
78
78
  end
79
+
80
+ it "measures a given value for a single key without a block" do
81
+ metrics.measure(:baz, value: 3.14)
82
+ expect(test_backend).to have_received(:report_measures).once.with(
83
+ "pliny.baz" => 3.14
84
+ )
85
+ end
86
+
87
+ it "measures a given value for multiple keys with a block" do
88
+ metrics.measure(:qux, :corge, value: 42) { }
89
+ expect(test_backend).to have_received(:report_measures).once.with(
90
+ "pliny.qux" => 42,
91
+ "pliny.corge" => 42
92
+ )
93
+ end
94
+
95
+ it "measures a value of 0 when no key or block is provided" do
96
+ metrics.measure(:waldo)
97
+ expect(test_backend).to have_received(:report_measures).once.with(
98
+ "pliny.waldo" => 0
99
+ )
100
+ end
79
101
  end
80
102
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pliny
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.20.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandur Leach
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-12-06 00:00:00.000000000 Z
12
+ date: 2016-12-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport