Class: Ant::Configuration::FeatureFlag::ABTest

Inherits:
Object
  • Object
show all
Defined in:
lib/ant/configs/feature_flag/ab_test.rb

Direct Known Subclasses

Canarying

Instance Method Summary collapse

Constructor Details

#initialize(configs) ⇒ ABTest

Returns a new instance of ABTest.



5
6
7
8
9
# File 'lib/ant/configs/feature_flag/ab_test.rb', line 5

def initialize(configs)
  @configs = configs
  @threshold = normalize_thershold(configs['threshold'])

end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ant/configs/feature_flag/ab_test.rb', line 24

def active?
  rand <= @threshold
end

#normalize_thershold(value) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ant/configs/feature_flag/ab_test.rb', line 11

def normalize_thershold(value)
  case value
  when Integer
    raise 'Value out of range' unless (0..100).cover?(value)

    value.to_f / 100
  when Float
    raise 'Value out of range' unless (0..1).cover?(value)

    value
  end
end