Skip to content

Commit dd5a244

Browse files
authored
feat: Add datafile accessor to config (#268)
* feat: Add datafile accessor to config
1 parent 5e02748 commit dd5a244

File tree

5 files changed

+12
-2
lines changed

5 files changed

+12
-2
lines changed

lib/optimizely/config/datafile_project_config.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class DatafileProjectConfig < ProjectConfig
2424
RUNNING_EXPERIMENT_STATUS = ['Running'].freeze
2525
RESERVED_ATTRIBUTE_PREFIX = '$opt_'
2626

27+
attr_reader :datafile
2728
attr_reader :account_id
2829
attr_reader :attributes
2930
attr_reader :audiences
@@ -62,6 +63,7 @@ def initialize(datafile, logger, error_handler)
6263

6364
config = JSON.parse(datafile)
6465

66+
@datafile = datafile
6567
@error_handler = error_handler
6668
@logger = logger
6769
@version = config['version']

lib/optimizely/optimizely_config.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
# Copyright 2019, Optimizely and contributors
3+
# Copyright 2019-2020, Optimizely and contributors
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ def config
2525
experiments_map_object = experiments_map
2626
features_map = get_features_map(experiments_map_object)
2727
{
28+
'datafile' => @project_config.datafile,
2829
'experimentsMap' => experiments_map_object,
2930
'featuresMap' => features_map,
3031
'revision' => @project_config.revision

lib/optimizely/project_config.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
# Copyright 2016-2019, Optimizely and contributors
3+
# Copyright 2016-2020, Optimizely and contributors
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@ class ProjectConfig
2020
# ProjectConfig is an interface capturing the experiment, variation and feature definitions.
2121
# The default implementation of ProjectConfig can be found in DatafileProjectConfig.
2222

23+
def datafile; end
24+
2325
def account_id; end
2426

2527
def attributes; end

spec/config/datafile_project_config_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
variable_to_modify['type'] = 'json'
4141
variable_to_modify.delete('subType')
4242

43+
expect(project_config.datafile).to eq(config_body_JSON)
4344
expect(project_config.account_id).to eq(config_body['accountId'])
4445
expect(project_config.attributes).to eq(config_body['attributes'])
4546
expect(project_config.audiences).to eq(config_body['audiences'])

spec/optimizely_config_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,8 @@
9494
it 'should return correct config revision' do
9595
expect(project_config.revision).to eq(optimizely_config['revision'])
9696
end
97+
98+
it 'should return correct datafile string' do
99+
expect(project_config.datafile).to eq(optimizely_config['datafile'])
100+
end
97101
end

0 commit comments

Comments
 (0)