Sha256: ac01382a423d4e725f22658ed745000121db463ddb6c3b95be33a0a71f5a015c
Contents?: true
Size: 1.17 KB
Versions: 25
Compression:
Stored size: 1.17 KB
Contents
module Flags def set_flag(name) unless get_flag(name) flag_flapped name, :on CityWatch.redis.setbit "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::flags", flag_position(name), 1 end end def clear_flag(name) if get_flag(name) flag_flapped name, :off CityWatch.redis.setbit "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::flags", flag_position(name), 0 end end def flag_flapped(name,new_val) puts "Flag flipped: #{name} -> #{new_val}" if CityWatch.debug? end def get_flag(name,host=host) @host = host CityWatch.redis.getbit("#{CityWatch.config[:prefix]}::#{host}::#{self.name}::flags", flag_position(name)) == 1 ? true : false end def get_flags(host=host) @host = host out = [] map = flag_map map.each_index do |idx| out << map[idx] if get_flag(map[idx]) end out end def flag_map_key "#{CityWatch.config[:prefix]}::#{self.name}::flag_map" end def flag_map CityWatch.redis.lrange flag_map_key, 0, -1 end def flag_position(name) if (map = flag_map) && map.include?(name.to_s) map.index(name.to_s) else new_flag(name) end end def new_flag(name) CityWatch.redis.rpush(flag_map_key, name) - 1 end end
Version data entries
25 entries across 25 versions & 1 rubygems