Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/rollout.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'zlib'

class Rollout

attr_accessor :redis, :groups
Expand Down Expand Up @@ -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