counters 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -81,7 +81,7 @@ Instantiate a StatsD instance:
81
81
  Counter = Counters::StatsD.new(:url => "udp://127.0.0.1:8125", :namespace => "crawler")
82
82
  </code></pre>
83
83
 
84
- See the file "samples/crawler.rb":blob/master/samples/crawler.rb for a more detailed example.
84
+ See the file "samples/crawler.rb":https://github.com/francois/counters/blob/master/samples/crawler.rb for a more detailed example.
85
85
 
86
86
  h2. LICENSE
87
87
 
@@ -2,9 +2,11 @@ require "benchmark"
2
2
 
3
3
  module Counters
4
4
  class Base
5
- attr_accessor :namespace
5
+
6
+ attr_writer :namespace
6
7
 
7
8
  def initialize(options={})
9
+ @options = options
8
10
  @namespace = options[:namespace]
9
11
  end
10
12
 
@@ -35,6 +37,16 @@ module Counters
35
37
  record_ping(namespaced_key(key))
36
38
  end
37
39
 
40
+ def namespace(*args)
41
+ if args.empty? then
42
+ @namespace
43
+ else
44
+ other = self.dup
45
+ other.namespace = [@namespace.to_s, args.first].join(".")
46
+ other
47
+ end
48
+ end
49
+
38
50
  def record_hit(key)
39
51
  raise "Subclass Responsibility Error: must be implemented in instances of #{self.class} but isn't"
40
52
  end
@@ -65,5 +77,6 @@ module Counters
65
77
  "#{namespace}.#{key}"
66
78
  end
67
79
  private :namespaced_key
80
+
68
81
  end
69
82
  end
@@ -1,3 +1,3 @@
1
1
  module Counters
2
- VERSION = "1.1.3"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -37,4 +37,9 @@ shared_examples_for "all counters" do
37
37
 
38
38
  value.should == "the returned value"
39
39
  end
40
+
41
+ it "should return a sub-namespaced counter on-demand" do
42
+ other = counter.namespace("sub")
43
+ other.namespace.should == "#{counter.namespace}.sub"
44
+ end
40
45
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: counters
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.3
5
+ version: 1.2.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-04-11 00:00:00 -04:00
13
+ date: 2011-05-31 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency