mirror of
https://github.com/jimeh/redistat.git
synced 2026-02-19 05:16:39 +00:00
cleaned up #sub_labels feature in Label object
This commit is contained in:
@@ -35,6 +35,18 @@ module Redistat
|
||||
@saved ||= false
|
||||
end
|
||||
|
||||
def parent
|
||||
@parent ||= self.class.new(parent_group)
|
||||
end
|
||||
|
||||
def parent_group
|
||||
groups[1]
|
||||
end
|
||||
|
||||
def group
|
||||
@raw.split(GROUP_SEPARATOR).last
|
||||
end
|
||||
|
||||
def groups
|
||||
return @groups if @groups
|
||||
@groups = []
|
||||
@@ -49,23 +61,17 @@ module Redistat
|
||||
@groups.reverse!
|
||||
end
|
||||
|
||||
def parent
|
||||
@parent ||= self.class.new(parent_group)
|
||||
end
|
||||
|
||||
def parent_group
|
||||
groups[1]
|
||||
end
|
||||
|
||||
def sub_group
|
||||
@raw.split(GROUP_SEPARATOR).last
|
||||
def sub_labels
|
||||
db.smembers("#{LABEL_INDEX}#{parent_group}").map { |member|
|
||||
self.class.new("#{parent_group}#{GROUP_SEPARATOR}#{member}")
|
||||
}
|
||||
end
|
||||
|
||||
def update_index
|
||||
groups.each do |group|
|
||||
label = self.class.new(group)
|
||||
break if label.parent_group.nil?
|
||||
db.sadd("#{LABEL_INDEX}#{label.parent_group}", label.sub_group) == "OK" ? true : false
|
||||
db.sadd("#{LABEL_INDEX}#{label.parent_group}", label.group) == "OK" ? true : false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user