Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make things private that should be private

  • Loading branch information...
commit 5c670f3d155bfb8d049d252d84548fc591b15179 1 parent 0bc7293
Rein Henrichs authored
Showing with 8 additions and 5 deletions.
  1. +3 −5 lib/statsd.rb
  2. +5 −0 spec/statsd_spec.rb
View
8 lib/statsd.rb
@@ -9,8 +9,6 @@
# statsd.increment 'garets'
# statsd.timing 'glork', 320
class Statsd
- attr_reader :host, :port
-
# @param [String] host your statsd host
# @param [Integer] port your statsd port
def initialize(host, port)
@@ -35,15 +33,15 @@ def count( stat, count, sample_rate=1); send stat, count, 'c', sample_rate end
# @param [Integer] sample_rate sample rate, 1 for always
def timing(stat, ms, sample_rate=1); send stat, ms, 'ms', sample_rate end
+ private
+
def sampled(sample_rate)
return if sample_rate < 1 and rand > sample_rate
yield
end
- private
-
def send(stat, delta, type, sample_rate)
- sampled(sample_rate) { socket.send("#{stat}:#{delta}|#{type}#{'|@' << sample_rate.to_s if sample_rate < 1}", 0, host, port) }
+ sampled(sample_rate) { socket.send("#{stat}:#{delta}|#{type}#{'|@' << sample_rate.to_s if sample_rate < 1}", 0, @host, @port) }
end
def socket; @socket ||= UDPSocket.new end
View
5 spec/statsd_spec.rb
@@ -9,7 +9,12 @@ def socket
before do
@statsd = Statsd.new('localhost', 1234)
+ class << @statsd
+ public :sampled # we need to test this
+ attr_reader :host, :port # we also need to test this
+ end
end
+
after { @statsd.socket.clear }
describe "#initialize" do
Please sign in to comment.
Something went wrong with that request. Please try again.