Allow for configurable group separator

This commit is contained in:
David Czarnecki
2012-04-18 14:44:36 -04:00
parent a9cf3938cf
commit fa182e618d
7 changed files with 71 additions and 8 deletions

View File

@@ -52,6 +52,8 @@ module Redistat
class << self
attr_writer :group_separator
def buffer
Buffer.instance
end
@@ -91,6 +93,10 @@ module Redistat
connection.flushdb
end
def group_separator
@group_separator ||= GROUP_SEPARATOR
end
end
end

View File

@@ -56,7 +56,7 @@ module Redistat
members = db.smembers("#{scope}#{LABEL_INDEX}#{@label}") || [] # older versions of Redis returns nil
members.map { |member|
child_label = [@label, member].reject { |i| i.nil? }
self.class.new(self.scope, child_label.join(GROUP_SEPARATOR), self.date, @options)
self.class.new(self.scope, child_label.join(Redistat.group_separator), self.date, @options)
}
end

View File

@@ -13,7 +13,7 @@ module Redistat
def self.join(*args)
args = args.map {|i| i.to_s}
self.new(args.reject {|i| i.blank? }.join(GROUP_SEPARATOR))
self.new(args.reject {|i| i.blank? }.join(Redistat.group_separator))
end
def initialize(str, opts = {})
@@ -48,16 +48,16 @@ module Redistat
end
def me
self.to_s.split(GROUP_SEPARATOR).last
self.to_s.split(Redistat.group_separator).last
end
def groups
return @groups unless @groups.nil?
@groups = []
parent = ""
self.to_s.split(GROUP_SEPARATOR).each do |part|
self.to_s.split(Redistat.group_separator).each do |part|
if !part.blank?
group = ((parent.blank?) ? "" : "#{parent}#{GROUP_SEPARATOR}") + part
group = ((parent.blank?) ? "" : "#{parent}#{Redistat.group_separator}") + part
@groups << Label.new(group)
parent = group
end

View File

@@ -66,13 +66,13 @@ module Redistat
def inject_group_summaries!(stats)
summaries = {}
stats.each do |key, value|
parts = key.to_s.split(GROUP_SEPARATOR)
parts = key.to_s.split(Redistat.group_separator)
parts.pop
if parts.size > 0
sum_parts = []
parts.each do |part|
sum_parts << part
sum_key = sum_parts.join(GROUP_SEPARATOR)
sum_key = sum_parts.join(Redistat.group_separator)
(summaries.has_key?(sum_key)) ? summaries[sum_key] += value : summaries[sum_key] = value
end
end