Class: Kameleoon::Configuration::FeatureFlag

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

Overview

Class for manage all feature flags with rules

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, segments, cdi) ⇒ FeatureFlag

Returns a new instance of FeatureFlag.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/kameleoon/configuration/feature_flag.rb', line 30

def initialize(hash, segments, cdi)
  @id = hash['id']
  @feature_key = hash['featureKey']
  @variations = Variation.create_from_array(hash['variations'])
  @default_variation_key = hash['defaultVariationKey']
  @me_group_name = hash['mutuallyExclusiveGroup']
  @environment_enabled = hash['environmentEnabled']
  @rules = Rule.create_from_array(hash['rules'], segments)
  bucketing_cd_id = hash['bucketingCustomDataId']
  @bucketing_custom_data_index = bucketing_cd_id ? cdi.get_custom_data_index_by_id(bucketing_cd_id) : nil
end

Instance Attribute Details

#bucketing_custom_data_indexObject (readonly)

Returns the value of attribute bucketing_custom_data_index.



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

def bucketing_custom_data_index
  @bucketing_custom_data_index
end

#default_variation_keyObject (readonly)

Returns the value of attribute default_variation_key.



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

def default_variation_key
  @default_variation_key
end

#environment_enabledObject (readonly)

Returns the value of attribute environment_enabled.



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

def environment_enabled
  @environment_enabled
end

#feature_keyObject (readonly)

Returns the value of attribute feature_key.



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

def feature_key
  @feature_key
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#me_group_nameObject (readonly)

Returns the value of attribute me_group_name.



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

def me_group_name
  @me_group_name
end

#rulesObject (readonly)

Returns the value of attribute rules.



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

def rules
  @rules
end

#variationsObject (readonly)

Returns the value of attribute variations.



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

def variations
  @variations
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

#get_variation_by_key(key) ⇒ Object



42
43
44
# File 'lib/kameleoon/configuration/feature_flag.rb', line 42

def get_variation_by_key(key)
  variations.select { |v| v.key == key }.first
end

#to_sObject



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

def to_s
  'FeatureFlag{' \
    "id:#{@id}," \
    "feature_key:'#{@feature_key}'," \
    "environment_enabled:#{@environment_enabled}," \
    "default_variation_key:'#{@default_variation_key}'," \
    "me_group_name:'#{@me_group_name}'," \
    "rules:#{@rules.size}," \
    "bucketing_custom_data_index:#{@bucketing_custom_data_index}" \
    '}'
end