Class: Kameleoon::Configuration::FeatureFlag

Inherits:
Experiment
  • Object
show all
Defined in:
lib/kameleoon/configuration/feature_flag.rb

Overview

Class for manage all experiments and old feature flags

Constant Summary collapse

STATUS_ACTIVE =
'ACTIVE'
FEATURE_STATUS_DEACTIVATED =
'DEACTIVATED'

Instance Attribute Summary collapse

Attributes inherited from Experiment

#deviations, #id, #respool_time, #site_enabled, #status, #targeting_segment, #variations

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feature_flag_hash) ⇒ FeatureFlag

Returns a new instance of FeatureFlag.



18
19
20
21
22
23
24
# File 'lib/kameleoon/configuration/feature_flag.rb', line 18

def initialize(feature_flag_hash)
  super(feature_flag_hash)
  @feature_status = feature_flag_hash['featureStatus']
  @identification_key = feature_flag_hash['identificationKey'] if feature_flag_hash['identificationKey']
  @exposition_rate = feature_flag_hash['expositionRate']
  @schedules = feature_flag_hash['schedules'] unless feature_flag_hash['schedules'].nil?
end

Instance Attribute Details

#exposition_rateObject

Returns the value of attribute exposition_rate.



12
13
14
# File 'lib/kameleoon/configuration/feature_flag.rb', line 12

def exposition_rate
  @exposition_rate
end

#feature_statusObject

Returns the value of attribute feature_status.



12
13
14
# File 'lib/kameleoon/configuration/feature_flag.rb', line 12

def feature_status
  @feature_status
end

#identification_keyObject

Returns the value of attribute identification_key.



12
13
14
# File 'lib/kameleoon/configuration/feature_flag.rb', line 12

def identification_key
  @identification_key
end

#schedulesObject

Returns the value of attribute schedules.



12
13
14
# File 'lib/kameleoon/configuration/feature_flag.rb', line 12

def schedules
  @schedules
end

Class Method Details

.create_from_array(array) ⇒ Object



14
15
16
# File 'lib/kameleoon/configuration/feature_flag.rb', line 14

def self.create_from_array(array)
  array&.map { |it| FeatureFlag.new(it) }
end

Instance Method Details

#is_scheduled_active(date) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/kameleoon/configuration/feature_flag.rb', line 26

def is_scheduled_active(date)
  current_status = @status == STATUS_ACTIVE
  if @feature_status == FEATURE_STATUS_DEACTIVATED || @schedules.empty?
    return current_status
  end
  @schedules.each do |schedule|
    if (schedule['dateStart'].nil? || Time.parse(schedule['dateStart']).to_i < date) &&
       (schedule['dateEnd'].nil? || Time.parse(schedule['dateEnd']).to_i > date)
      return true
    end
  end
  false
end