Class: Optimizely::OptimizelyConfig

Inherits:
Object
  • Object
show all
Includes:
ConditionTreeEvaluator
Defined in:
lib/optimizely/optimizely_config.rb

Constant Summary

Constants included from ConditionTreeEvaluator

ConditionTreeEvaluator::AND_CONDITION, ConditionTreeEvaluator::EVALUATORS_BY_OPERATOR_TYPE, ConditionTreeEvaluator::NOT_CONDITION, ConditionTreeEvaluator::OPERATORS, ConditionTreeEvaluator::OR_CONDITION

Instance Method Summary collapse

Methods included from ConditionTreeEvaluator

and_evaluator, evaluate, not_evaluator, or_evaluator

Constructor Details

#initialize(project_config, logger = nil) ⇒ OptimizelyConfig

Returns a new instance of OptimizelyConfig.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/optimizely/optimizely_config.rb', line 22

def initialize(project_config, logger = nil)
  @project_config = project_config
  @logger = logger || NoOpLogger.new
  @rollouts = @project_config.rollouts
  @audiences = []
  audience_id_lookup_dict = {}

  @project_config.typed_audiences.each do |typed_audience|
    @audiences.push(
      'id' => typed_audience['id'],
      'name' => typed_audience['name'],
      'conditions' => typed_audience['conditions'].to_json
    )
    audience_id_lookup_dict[typed_audience['id']] = typed_audience['id']
  end

  @project_config.audiences.each do |audience|
    next unless !audience_id_lookup_dict.key?(audience['id']) && (audience['id'] != '$opt_dummy_audience')

    @audiences.push(
      'id' => audience['id'],
      'name' => audience['name'],
      'conditions' => audience['conditions']
    )
  end
end

Instance Method Details

#configObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/optimizely/optimizely_config.rb', line 49

def config
  experiments_map_object = experiments_map
  features_map = get_features_map(experiments_id_map)
  {
    'sdkKey' => @project_config.sdk_key,
    'datafile' => @project_config.datafile,
    # This experimentsMap is for experiments of legacy projects only.
    # For flag projects, experiment keys are not guaranteed to be unique
    # across multiple flags, so this map may not include all experiments
    # when keys conflict. Use experimentRules and deliveryRules instead.
    'experimentsMap' => experiments_map_object,
    'featuresMap' => features_map,
    'revision' => @project_config.revision,
    'attributes' => get_attributes_list(@project_config.attributes),
    'audiences' => @audiences,
    'events' => get_events_list(@project_config.events),
    'environmentKey' => @project_config.environment_key
  }
end