class Ant::Configuration::FeatureFlag::Canarying

Public Class Methods

new(configs) click to toggle source
# 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

Public Instance Methods

active?() click to toggle source
# File lib/ant/configs/feature_flag/canarying.rb, line 13
def active?
  rand <= threshold_calculation
end
initial_time(time) click to toggle source
# 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_calculation() click to toggle source
# 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