mirror of
https://github.com/jimeh/redistat.git
synced 2026-02-19 05:16:39 +00:00
Improve Buffer's unique key identifier
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user