Class: Ant::Configuration::FeatureFlag::Canarying

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



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

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)


13
14
15
# File 'lib/ant/configs/feature_flag/canarying.rb', line 13

def active?
  rand <= threshold_calculation
end

#initial_time(time) ⇒ Object



21
22
23
24
25
# File 'lib/ant/configs/feature_flag/canarying.rb', line 21

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

  Time.parse(time)
end

#threshold_calculationObject



17
18
19
# File 'lib/ant/configs/feature_flag/canarying.rb', line 17

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