Browse files

Allow setting a nil host. Will resolve to localhost ultimately.

  • Loading branch information...
1 parent c899861 commit 0f7f9e6c689f05e9ef42265a25ee2512e797c7cb @jeremy committed Dec 3, 2011
Showing with 15 additions and 6 deletions.
  1. +10 −6 lib/statsd.rb
  2. +5 −0 spec/statsd_spec.rb
View
16 lib/statsd.rb
@@ -50,12 +50,16 @@ def namespace=(namespace) #:nodoc:
# If the argument is a hostname, resolve it to an IP address.
def host=(host) #:nodoc:
- require 'ipaddr'
- begin
- @host = IPAddr.new(host).to_s
- rescue ArgumentError
- require 'resolv'
- @host = Resolv.getaddress(host)
+ if host
+ require 'ipaddr'
+ begin
+ @host = IPAddr.new(host).to_s
+ rescue ArgumentError
+ require 'resolv'
+ @host = Resolv.getaddress(host)
+ end
+ else
+ @host = nil
end
end
View
5 spec/statsd_spec.rb
@@ -40,6 +40,11 @@ class Statsd
@statsd.host = 'localhost'
@statsd.host.must_equal '127.0.0.1'
end
+
+ it "should not resolve nil host" do
+ @statsd.host = nil
+ @statsd.host.must_equal nil
+ end
end
describe "#increment" do

0 comments on commit 0f7f9e6

Please sign in to comment.