lib/feature_guard/guard.rb in feature_guard-0.1.2 vs lib/feature_guard/guard.rb in feature_guard-0.2.1

- old
+ new

@@ -5,19 +5,19 @@ @feature_name = _feature_name end # binary flag methods (enabled/disabled) def disable - redis.set(flag_key, 0) + redis.hset(FeatureGuard.flags_hkey, feature_name, 0) end def enable - redis.set(flag_key, 1) + redis.hset(FeatureGuard.flags_hkey, feature_name, 1) end def enabled? - redis.get(flag_key).tap { |v| return (!v.nil? && v.to_i > 0) } + redis.hget(FeatureGuard.flags_hkey, feature_name).tap { |v| return (!v.nil? && v.to_i > 0) } rescue false end def toggle @@ -33,37 +33,25 @@ def bump_ramp(amount = 10.0) set_ramp(ramp_val + amount) end def ramp_val - redis.get(ramp_key).to_f + redis.hget(FeatureGuard.ramps_hkey, feature_name).to_f end def set_ramp(new_val) new_val = new_val.to_f new_val = 100.0 if new_val > 100.0 new_val = 0.0 if new_val < 0.0 - redis.set(ramp_key, new_val) + redis.hset(FeatureGuard.ramps_hkey, feature_name, new_val) new_val end private - def feature_key - @feature_key ||= feature_name.to_s.split.join('_') - end - - def flag_key - @flag_key ||= "fgf_#{feature_key}" - end - - def ramp_key - @ramp_key ||= "fgr_#{feature_key}" - end - def hashed_val(s) - (Digest::MD5.hexdigest("#{ramp_key}_#{s}").to_i(16) % 10000).to_f / 100.0 + (Digest::MD5.hexdigest("#{feature_name}_#{s}").to_i(16) % 10000).to_f / 100.0 end def random_val rand * 100.0 end