tabs 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/tabs/tabs.rb CHANGED
@@ -19,20 +19,18 @@ module Tabs
19
19
  Config.redis
20
20
  end
21
21
 
22
- def increment_counter(key)
23
- raise UnknownMetricError.new("Unknown metric: #{key}") unless metric_exists?(key)
24
- raise MetricTypeMismatchError.new("Only counter metrics can be incremented") unless metric_type(key) == "counter"
25
- get_metric(key).increment
22
+ def config
23
+ Config
26
24
  end
27
25
 
28
- def counter_total(key, period=nil)
29
- raise UnknownMetricError.new("Unknown metric: #{key}") unless metric_exists?(key)
26
+ def increment_counter(key)
27
+ create_metric(key, "counter") unless metric_exists?(key)
30
28
  raise MetricTypeMismatchError.new("Only counter metrics can be incremented") unless metric_type(key) == "counter"
31
- get_metric(key).total
29
+ get_metric(key).increment
32
30
  end
33
31
 
34
32
  def record_value(key, value)
35
- raise UnknownMetricError.new("Unknown metric: #{key}") unless metric_exists?(key)
33
+ create_metric(key, "value") unless metric_exists?(key)
36
34
  raise MetricTypeMismatchError.new("Only value metrics can record a value") unless metric_type(key) == "value"
37
35
  get_metric(key).record(value)
38
36
  end
@@ -51,6 +49,12 @@ module Tabs
51
49
  metric_klass(type).new(key)
52
50
  end
53
51
 
52
+ def counter_total(key, period=nil)
53
+ raise UnknownMetricError.new("Unknown metric: #{key}") unless metric_exists?(key)
54
+ raise MetricTypeMismatchError.new("Only counter metrics can be incremented") unless metric_type(key) == "counter"
55
+ get_metric(key).total
56
+ end
57
+
54
58
  def get_stats(key, period, resolution)
55
59
  raise UnknownMetricError.new("Unknown metric: #{key}") unless metric_exists?(key)
56
60
  metric = get_metric(key)
data/lib/tabs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tabs
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
3
3
  end
@@ -87,15 +87,17 @@ describe Tabs do
87
87
 
88
88
  describe "#increment_counter" do
89
89
 
90
- it "raises an Tabs::UnknownMetricError if the metric does not exist" do
91
- lambda { Tabs.increment_counter("foo") }.should raise_error(Tabs::UnknownMetricError)
92
- end
93
-
94
90
  it "raises a Tabs::MetricTypeMismatchError if the metric is the wrong type" do
95
91
  Tabs.create_metric("foo", "value")
96
92
  lambda { Tabs.increment_counter("foo") }.should raise_error(Tabs::MetricTypeMismatchError)
97
93
  end
98
94
 
95
+ it "creates the metric if it doesn't exist" do
96
+ expect(Tabs.metric_exists?("foo")).to be_false
97
+ lambda { Tabs.increment_counter("foo") }.should_not raise_error
98
+ expect(Tabs.metric_exists?("foo")).to be_true
99
+ end
100
+
99
101
  it "calls increment on the metric" do
100
102
  metric = Tabs.create_metric("foo", "counter")
101
103
  Tabs.stub(get_metric: metric)
@@ -105,10 +107,12 @@ describe Tabs do
105
107
 
106
108
  end
107
109
 
108
- describe "#increment_counter" do
110
+ describe "#record_value" do
109
111
 
110
- it "raises an Tabs::UnknownMetricError if the metric does not exist" do
111
- lambda { Tabs.record_value("foo", 27) }.should raise_error(Tabs::UnknownMetricError)
112
+ it "creates the metric if it doesn't exist" do
113
+ expect(Tabs.metric_exists?("foo")).to be_false
114
+ lambda { Tabs.record_value("foo", 38) }.should_not raise_error
115
+ expect(Tabs.metric_exists?("foo")).to be_true
112
116
  end
113
117
 
114
118
  it "raises a Tabs::MetricTypeMismatchError if the metric is the wrong type" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: