Class: Kybus::Configuration::FeatureFlag::ABTest

Inherits:
Object
  • Object
show all
Defined in:
lib/kybus/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.



7
8
9
10
# File 'lib/kybus/configs/feature_flag/ab_test.rb', line 7

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

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/kybus/configs/feature_flag/ab_test.rb', line 25

def active?
  rand <= @threshold
end

#normalize_thershold(value) ⇒ Object



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

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