Skip to content
This repository
Browse code

Make things private that should be private

  • Loading branch information...
commit 5c670f3d155bfb8d049d252d84548fc591b15179 1 parent 0bc7293
Rein Henrichs authored

Showing 2 changed files with 8 additions and 5 deletions. Show diff stats Hide diff stats

  1. +3 5 lib/statsd.rb
  2. +5 0 spec/statsd_spec.rb
8 lib/statsd.rb
@@ -9,8 +9,6 @@
9 9 # statsd.increment 'garets'
10 10 # statsd.timing 'glork', 320
11 11 class Statsd
12   - attr_reader :host, :port
13   -
14 12 # @param [String] host your statsd host
15 13 # @param [Integer] port your statsd port
16 14 def initialize(host, port)
@@ -35,15 +33,15 @@ def count( stat, count, sample_rate=1); send stat, count, 'c', sample_rate end
35 33 # @param [Integer] sample_rate sample rate, 1 for always
36 34 def timing(stat, ms, sample_rate=1); send stat, ms, 'ms', sample_rate end
37 35
  36 + private
  37 +
38 38 def sampled(sample_rate)
39 39 return if sample_rate < 1 and rand > sample_rate
40 40 yield
41 41 end
42 42
43   - private
44   -
45 43 def send(stat, delta, type, sample_rate)
46   - sampled(sample_rate) { socket.send("#{stat}:#{delta}|#{type}#{'|@' << sample_rate.to_s if sample_rate < 1}", 0, host, port) }
  44 + sampled(sample_rate) { socket.send("#{stat}:#{delta}|#{type}#{'|@' << sample_rate.to_s if sample_rate < 1}", 0, @host, @port) }
47 45 end
48 46
49 47 def socket; @socket ||= UDPSocket.new end
5 spec/statsd_spec.rb
@@ -9,7 +9,12 @@ def socket
9 9
10 10 before do
11 11 @statsd = Statsd.new('localhost', 1234)
  12 + class << @statsd
  13 + public :sampled # we need to test this
  14 + attr_reader :host, :port # we also need to test this
  15 + end
12 16 end
  17 +
13 18 after { @statsd.socket.clear }
14 19
15 20 describe "#initialize" do

0 comments on commit 5c670f3

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