Skip to content
Browse files

Setting host or port to nil sets to defaults

  • Loading branch information...
1 parent 0f7f9e6 commit 2cc97db5c58b76b35ec1a5a8c235fd1d585a242f @jeremy committed
Showing with 13 additions and 4 deletions.
  1. +6 −2 lib/statsd.rb
  2. +7 −2 spec/statsd_spec.rb
View
8 lib/statsd.rb
@@ -37,7 +37,7 @@ def logger=(logger) #:nodoc:
# @param [String] host your statsd host
# @param [Integer] port your statsd port
- def initialize(host='127.0.0.1', port=8125)
+ def initialize(host = '127.0.0.1', port = 8125)
self.host, self.port = host, port
@prefix = nil
@socket = UDPSocket.new
@@ -59,10 +59,14 @@ def host=(host) #:nodoc:
@host = Resolv.getaddress(host)
end
else
- @host = nil
+ @host = '127.0.0.1'
end
end
+ def port=(port) #:nodoc:
+ @port = port || 8125
+ end
+
# Sends an increment (count = 1) for the given stat to the statsd server.
#
# @param [String] stat stat name
View
9 spec/statsd_spec.rb
@@ -41,9 +41,14 @@ class Statsd
@statsd.host.must_equal '127.0.0.1'
end
- it "should not resolve nil host" do
+ it "should set nil host to default" do
@statsd.host = nil
- @statsd.host.must_equal nil
+ @statsd.host.must_equal '127.0.0.1'
+ end
+
+ it "should set nil port to default" do
+ @statsd.port = nil
+ @statsd.port.must_equal 8125
end
end

0 comments on commit 2cc97db

Please sign in to comment.
Something went wrong with that request. Please try again.