diff --git a/lib/rollout.rb b/lib/rollout.rb index 37eb03e..f1c901d 100644 --- a/lib/rollout.rb +++ b/lib/rollout.rb @@ -1,3 +1,5 @@ +require 'zlib' + class Rollout attr_accessor :redis, :groups @@ -89,6 +91,14 @@ def user_within_active_percentage?(feature, user) percentage = percentage(feature) return false if percentage.nil? - user.id % 10 < percentage.to_i / 10 + combined_hash(user.id, feature) % 100 < percentage.to_i + end + + def combined_hash(*objects) + objects.inject(0) { |m,o| m + integer_hash(o) } + end + + def integer_hash(obj) + Zlib.crc32 obj.to_s end end