From b24a1a3a2d285dffff5aa2e360aa7311a35beb24 Mon Sep 17 00:00:00 2001 From: Sean Treadway Date: Thu, 29 Sep 2011 19:21:29 +0200 Subject: [PATCH] Loosen privacy of Client#write to protected so subclasses can decorate metrics before the transport --- lib/statsy.rb | 4 ++-- test/statsy_test.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/statsy.rb b/lib/statsy.rb index a2fdfc8..2d70cb4 100644 --- a/lib/statsy.rb +++ b/lib/statsy.rb @@ -1,7 +1,7 @@ # Client to access statsd service authored by etsy. Yay etsy! # https://github.com/etsy/statsd module Statsy - VERSION="0.1.2" + VERSION="0.1.3" module Transport require 'socket' @@ -119,7 +119,7 @@ def batch self end - private + protected def write(stat, value, modifier, sampling) if sampling < 1 if Kernel.rand < sampling diff --git a/test/statsy_test.rb b/test/statsy_test.rb index 75e517e..8789319 100644 --- a/test/statsy_test.rb +++ b/test/statsy_test.rb @@ -1,6 +1,32 @@ require 'test/unit' require File.expand_path('../../lib/statsy', __FILE__) +class SubclassUnit < Test::Unit::TestCase + class Frob < Statsy::Client + protected + def write(stat, value, modifier, sampling) + super("frob", value, modifier, sampling) + end + end + + def setup + @transport = Statsy::Transport::Queue.new + @client = Frob.new(@transport) + end + + def test_subclass_should_override_write_with_full_frobbing + transport = Statsy::Transport::Queue.new + client = Statsy::Client.new() + + @client.increment("foo.stat", 1) + @client.measure("foo.mess", 100) + + assert_equal 2, @transport.size + assert_equal "frob:1|c", @transport.shift + assert_equal "frob:100|ms", @transport.shift + end +end + class Unit < Test::Unit::TestCase def setup @transport = Statsy::Transport::Queue.new