Class: Kybus::Configuration::FeatureFlag::Canarying

Inherits:
ABTest
  • Object
show all
Defined in:
lib/kybus/configs/feature_flag/canarying.rb

Instance Method Summary collapse

Methods inherited from ABTest

#normalize_thershold

Constructor Details

#initialize(configs) ⇒ Canarying

Returns a new instance of Canarying.



7
8
9
10
11
12
13
# File 'lib/kybus/configs/feature_flag/canarying.rb', line 7

def initialize(configs)
  @enabled = configs
  @initial_time = initial_time(configs['starting_hour'])
  @threshold = normalize_thershold(configs['initial'] || 0)
  @step = normalize_thershold(configs['step'])
  @step_duration = configs['step_duration']
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/kybus/configs/feature_flag/canarying.rb', line 15

def active?
  rand <= threshold_calculation
end

#initial_time(time) ⇒ Object



23
24
25
26
27
# File 'lib/kybus/configs/feature_flag/canarying.rb', line 23

def initial_time(time)
  return Time.now if time.nil?

  Time.parse(time)
end

#threshold_calculationObject



19
20
21
# File 'lib/kybus/configs/feature_flag/canarying.rb', line 19

def threshold_calculation
  @threshold + (Time.now - @initial_time).to_i / @step_duration.to_i * @step
end