Class: Kybus::Configuration::FeatureFlag::Canarying
- Defined in:
- lib/kybus/configs/feature_flag/canarying.rb
Instance Method Summary collapse
- #active? ⇒ Boolean
- #initial_time(time) ⇒ Object
-
#initialize(configs) ⇒ Canarying
constructor
A new instance of Canarying.
- #threshold_calculation ⇒ Object
Methods inherited from ABTest
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
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_calculation ⇒ Object
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 |