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

Version Path
city-watch-0.7.9 lib/city_watch/util/flags.rb
city-watch-0.7.8 lib/city_watch/util/flags.rb
city-watch-0.7.7 lib/city_watch/util/flags.rb
city-watch-0.7.6 lib/city_watch/util/flags.rb
city-watch-0.7.5 lib/city_watch/util/flags.rb
city-watch-0.7.4 lib/city_watch/util/flags.rb
city-watch-0.7.3 lib/city_watch/util/flags.rb
city-watch-0.7.2 lib/city_watch/util/flags.rb
city-watch-0.7.1 lib/city_watch/util/flags.rb
city-watch-0.7.0 lib/city_watch/util/flags.rb
city-watch-0.6.9 lib/city_watch/util/flags.rb
city-watch-0.6.8 lib/city_watch/util/flags.rb
city-watch-0.6.7 lib/city_watch/util/flags.rb
city-watch-0.6.6 lib/city_watch/util/flags.rb
city-watch-0.6.5 lib/city_watch/util/flags.rb
city-watch-0.6.4 lib/city_watch/util/flags.rb
city-watch-0.6.3 lib/city_watch/util/flags.rb
city-watch-0.6.2 lib/city_watch/util/flags.rb
city-watch-0.6.1 lib/city_watch/util/flags.rb
city-watch-0.6.0 lib/city_watch/util/flags.rb