Improve Buffer's unique key identifier

This commit is contained in:
2012-04-17 16:31:31 +01:00
parent 6502fc0f62
commit 5087f4ef45
2 changed files with 11 additions and 6 deletions

View File

@@ -95,12 +95,15 @@ module Redistat
end
end
# depth_limit is not needed as it's evident in key.to_s
def buffer_key(key, opts)
# depth_limit is not needed as it's evident in key.to_s
opts_index = Summary.default_options.keys.sort { |a,b| a.to_s <=> b.to_s }.map do |k|
opts[k] if opts.has_key?(k)
# covert keys to strings, as sorting a Hash with Symbol keys fails on
# Ruby 1.8.x.
opts = opts.inject({}) do |result, (k, v)|
result[k.to_s] = v
result
end
"#{key.to_s}:#{opts_index.join(':')}"
"#{key.to_s}:#{opts.sort.flatten.join(':')}"
end
end

View File

@@ -78,9 +78,11 @@ describe Redistat::Buffer do
it "should build #buffer_key correctly" do
opts = {:enable_grouping => true, :label_indexing => false, :connection_ref => nil}
@buffer.send(:buffer_key, @key, opts).should == "#{@key.to_s}::true:false"
@buffer.send(:buffer_key, @key, opts).should ==
"#{@key.to_s}:connection_ref::enable_grouping:true:label_indexing:false"
opts = {:enable_grouping => false, :label_indexing => true, :connection_ref => :omg}
@buffer.send(:buffer_key, @key, opts).should == "#{@key.to_s}:omg:false:true"
@buffer.send(:buffer_key, @key, opts).should ==
"#{@key.to_s}:connection_ref:omg:enable_grouping:false:label_indexing:true"
end
describe "Buffering" do