counters 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,9 +10,9 @@ module Counters
10
10
  @namespace = options[:namespace]
11
11
  end
12
12
 
13
- def hit(key)
13
+ def hit(key, value=1)
14
14
  validate(key)
15
- record_hit(namespaced_key(key))
15
+ record_hit(namespaced_key(key), value)
16
16
  end
17
17
 
18
18
  def magnitude(key, value)
@@ -47,7 +47,7 @@ module Counters
47
47
  end
48
48
  end
49
49
 
50
- def record_hit(key)
50
+ def record_hit(key, value)
51
51
  raise "Subclass Responsibility Error: must be implemented in instances of #{self.class} but isn't"
52
52
  end
53
53
  protected :record_hit
@@ -27,8 +27,8 @@ module Counters
27
27
  end
28
28
  end
29
29
 
30
- def record_hit(key)
31
- @logger.info "hit: #{key}"
30
+ def record_hit(key, increment)
31
+ @logger.info "hit: #{key}#{ increment == 1 ? "" : ": #{increment}"}"
32
32
  end
33
33
 
34
34
  def record_magnitude(key, magnitude)
@@ -13,8 +13,8 @@ module Counters
13
13
  @pings = Hash.new
14
14
  end
15
15
 
16
- def record_hit(key)
17
- @hits[key] += 1
16
+ def record_hit(key, increment)
17
+ @hits[key] += increment
18
18
  end
19
19
 
20
20
  def record_ping(key)
@@ -10,8 +10,8 @@ module Counters
10
10
  @base_key = options.fetch(:base_key) { raise "Missing :base_key from #{options.inspect}" }
11
11
  end
12
12
 
13
- def record_hit(key)
14
- @redis.hincrby(@base_key, "hits.#{key}", 1)
13
+ def record_hit(key, increment)
14
+ @redis.hincrby(@base_key, "hits.#{key}", increment)
15
15
  end
16
16
 
17
17
  def record_magnitude(key, amount)
@@ -27,8 +27,8 @@ module Counters
27
27
  socket.send("pings.#{key}:1|c", 0, host, port)
28
28
  end
29
29
 
30
- def record_hit(key)
31
- socket.send("hits.#{key}:1|c", 0, host, port)
30
+ def record_hit(key, increment)
31
+ socket.send("hits.#{key}:#{increment}|c", 0, host, port)
32
32
  end
33
33
 
34
34
  # StatsD expects millisecond resolution
@@ -1,3 +1,3 @@
1
1
  module Counters
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -38,6 +38,10 @@ shared_examples_for "all counters" do
38
38
  value.should == "the returned value"
39
39
  end
40
40
 
41
+ it "should allow hitting with a specific value increment" do
42
+ lambda { counter.hit "tada", 17 }.should_not raise_error
43
+ end
44
+
41
45
  it "should return a sub-namespaced counter on-demand" do
42
46
  other = counter.namespace("sub")
43
47
  other.namespace.should == "#{counter.namespace}.sub"
@@ -90,5 +90,11 @@ describe Counters::StatsD do
90
90
  socket.should_receive(:send).with(/^pings\.beer\.tulip\b/, anything, anything, anything)
91
91
  counter.ping "tulip"
92
92
  end
93
+
94
+ it "should increment with the #hit value" do
95
+ counter.namespace = "pow"
96
+ socket.should_receive(:send).with(/^hits\.pow\.loudness:17\b/, anything, anything, anything)
97
+ counter.hit "loudness", 17
98
+ end
93
99
  end
94
100
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: counters
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.0
5
+ version: 1.3.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Fran\xC3\xA7ois Beausoleil"
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-31 00:00:00 -04:00
13
+ date: 2011-06-01 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency