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