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) ⇒ FeatureFlag

Returns a new instance of FeatureFlag.



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

def initialize(hash)
  @id = hash['id']
  @feature_key = hash['featureKey']
  @variations = Variation.create_from_array(hash['variations'])
  @default_variation_key = hash['defaultVariationKey']
  @environment_enabled = hash['environmentEnabled']
  @rules = Rule.create_from_array(hash['rules'])
end

Instance Attribute Details

#default_variation_keyObject

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

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

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

Returns the value of attribute id.



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

def id
  @id
end

#rulesObject

Returns the value of attribute rules.



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

def rules
  @rules
end

#variationsObject

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



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

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

Instance Method Details

#get_variation_by_key(key) ⇒ Object



36
37
38
# File 'lib/kameleoon/configuration/feature_flag.rb', line 36

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

#to_sObject



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

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