counters 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,25 @@
1
1
  require "socket"
2
+ require "uri"
2
3
 
3
4
  module Counters
4
5
  class StatsD < Counters::Base
5
6
  attr_reader :host, :port, :socket
6
7
 
7
- def initialize(host, port, options={})
8
+ def initialize(*args)
9
+ options = args.last.is_a?(Hash) ? args.pop : Hash.new
8
10
  super(options)
9
11
 
10
- @host, @port = host, port
12
+ url = case args.length
13
+ when 0
14
+ options.fetch(:url) { raise ArgumentError, "Missing :url key from #{args.first}" }
15
+ when 2
16
+ "statsd://#{args.first}:#{args.last}"
17
+ else
18
+ raise ArgumentError, "Expected either a Hash or a host and port arguments, found: #{args.inspect}"
19
+ end
20
+
21
+ uri = URI.parse(url)
22
+ @host, @port = uri.host, uri.port
11
23
  @socket = options.fetch(:socket) { UDPSocket.new }
12
24
  end
13
25
 
@@ -1,3 +1,3 @@
1
1
  module Counters
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
@@ -1,5 +1,19 @@
1
1
  require "spec_helper"
2
2
 
3
+ describe Counters::StatsD, "#initialize" do
4
+ it "should accept a Hash with a :url key" do
5
+ counter = Counters::StatsD.new(:url => "statsd://statsd.internal:9991")
6
+ counter.host.should == "statsd.internal"
7
+ counter.port.should == 9991
8
+ end
9
+
10
+ it "should accept a host/port pair" do
11
+ counter = Counters::StatsD.new("127.0.0.1", 8125)
12
+ counter.host.should == "127.0.0.1"
13
+ counter.port.should == 8125
14
+ end
15
+ end
16
+
3
17
  describe Counters::StatsD do
4
18
  let :socket do
5
19
  double("socket")
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: counters
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.1
5
+ version: 1.1.2
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-03-30 00:00:00 -04:00
13
+ date: 2011-04-07 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency