Class: Gitlab::Experiment::Rollout::Percent
- Inherits:
-
Base
- Object
- Base
- Gitlab::Experiment::Rollout::Percent
show all
- Defined in:
- lib/gitlab/experiment/rollout/percent.rb
Instance Attribute Summary
Attributes inherited from Base
#experiment
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #rollout_for
Instance Method Details
#execute ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/gitlab/experiment/rollout/percent.rb', line 9
def execute
crc = normalized_id
total = 0
case distribution_rules
when Array then variant_names[distribution_rules.find_index { |percent| crc % 100 <= total += percent }]
when Hash then distribution_rules.find { |_, percent| crc % 100 <= total += percent }.first
else variant_names[crc % variant_names.length]
end
end
|
#validate! ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/gitlab/experiment/rollout/percent.rb', line 23
def validate!
case distribution_rules
when nil then nil
when Array, Hash
if distribution_rules.length != variant_names.length
raise InvalidRolloutRules, "the distribution rules don't match the number of variants defined"
end
else
raise InvalidRolloutRules, 'unknown distribution options type'
end
end
|