Skip to content

Commit 2c0732b

Browse files
committed
Fix lint issues
1 parent 48846e7 commit 2c0732b

3 files changed

Lines changed: 43 additions & 48 deletions

File tree

lib/optimizely/config/datafile_project_config.rb

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class DatafileProjectConfig < ProjectConfig
3333
:group_id_map, :rollout_id_map, :rollout_experiment_id_map, :variation_id_map,
3434
:variation_id_to_variable_usage_map, :variation_key_map, :variation_id_map_by_experiment_id,
3535
:variation_key_map_by_experiment_id, :flag_variation_map, :integration_key_map, :integrations,
36-
:public_key_for_odp, :host_for_odp, :all_segments, :region, :holdouts, :holdout_id_map,
36+
:public_key_for_odp, :host_for_odp, :all_segments, :region, :holdouts, :holdout_id_map,
3737
:global_holdouts, :included_holdouts, :excluded_holdouts, :flag_holdouts_map
3838
# Boolean - denotes if Optimizely should remove the last block of visitors' IP address before storing event data
3939
attr_reader :anonymize_ip
@@ -127,8 +127,7 @@ def initialize(datafile, logger, error_handler)
127127
if holdout['includedFlags'].nil? || holdout['includedFlags'].empty?
128128
@global_holdouts[holdout['id']] = holdout
129129

130-
if holdout['excludedFlags']
131-
holdout['excludedFlags'].each do |flag_id|
130+
holdout['excludedFlags']&.each do |flag_id|
132131
@excluded_holdouts[flag_id] ||= []
133132
@excluded_holdouts[flag_id] << holdout
134133
end
@@ -631,7 +630,7 @@ def get_holdouts_for_flag(flag_key)
631630
# Helper method to get holdouts from an applied feature flag
632631
#
633632
# flag_key - Key of the feature flag
634-
#
633+
#
635634
# Returns the holdouts that apply for a specific flag
636635

637636
feature_flag = @feature_flag_key_map[flag_key]
@@ -659,30 +658,26 @@ def get_holdouts_for_flag(flag_key)
659658
end
660659

661660
# Add holdouts that specifically include this flag
662-
if @included_holdouts.key?(flag_id)
663-
holdouts.concat(@included_holdouts[flag_id])
664-
end
661+
holdouts.concat(@included_holdouts[flag_id]) if @included_holdouts.key?(flag_id)
665662

666663
# Cache the result
667664
@flag_holdouts_map[flag_id] = holdouts
668665

669-
return holdouts
666+
holdouts
670667
end
671668

672669
def get_holdout(holdout_id)
673670
# Helper method to get holdout from holdout ID
674671
#
675672
# holdout_id - ID of the holdout
676-
#
673+
#
677674
# Returns the holdout
678675

679676
holdout = @holdout_id_map[holdout_id]
680-
if holdout
681-
return holdout
682-
else
683-
@logger.log Logger::ERROR, "Holdout with ID '#{holdout_id}' not found."
684-
return nil
685-
end
677+
return holdout if holdout
678+
679+
@logger.log Logger::ERROR, "Holdout with ID '#{holdout_id}' not found."
680+
nil
686681
end
687682
end
688683
end

spec/config/datafile_project_config_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,8 +1238,8 @@
12381238
describe '#get_holdouts_for_flag' do
12391239
let(:config_with_holdouts) do
12401240
Optimizely::DatafileProjectConfig.new(
1241-
OptimizelySpec::CONFIG_BODY_WITH_HOLDOUTS_JSON,
1242-
logger,
1241+
OptimizelySpec::CONFIG_BODY_WITH_HOLDOUTS_JSON,
1242+
logger,
12431243
error_handler
12441244
)
12451245
end
@@ -1288,8 +1288,8 @@
12881288
describe '#get_holdout' do
12891289
let(:config_with_holdouts) do
12901290
Optimizely::DatafileProjectConfig.new(
1291-
OptimizelySpec::CONFIG_BODY_WITH_HOLDOUTS_JSON,
1292-
logger,
1291+
OptimizelySpec::CONFIG_BODY_WITH_HOLDOUTS_JSON,
1292+
logger,
12931293
error_handler
12941294
)
12951295
end
@@ -1338,7 +1338,7 @@
13381338

13391339
expect(result).to be_nil
13401340
expect(spy_logger).to have_received(:log).with(
1341-
Logger::ERROR,
1341+
Logger::ERROR,
13421342
"Holdout with ID 'invalid_holdout_id' not found."
13431343
)
13441344
end
@@ -1348,7 +1348,7 @@
13481348

13491349
expect(result).not_to be_nil
13501350
expect(spy_logger).not_to have_received(:log).with(
1351-
Logger::ERROR,
1351+
Logger::ERROR,
13521352
anything
13531353
)
13541354
end
@@ -1363,13 +1363,13 @@
13631363
'key' => 'global',
13641364
'status' => 'Running',
13651365
'includedFlags' => [],
1366-
'excludedFlags' => ['boolean_feature', 'string_single_variable_feature']
1366+
'excludedFlags' => %w[boolean_feature string_single_variable_feature]
13671367
},
13681368
{
13691369
'id' => 'specific_holdout',
13701370
'key' => 'specific',
1371-
'status' => 'Running',
1372-
'includedFlags' => ['multi_variate_feature', 'empty_feature'],
1371+
'status' => 'Running',
1372+
'includedFlags' => %w[multi_variate_feature empty_feature],
13731373
'excludedFlags' => []
13741374
},
13751375
{

spec/spec_params.rb

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,30 +1940,30 @@ module OptimizelySpec
19401940
CONFIG_DICT_WITH_INTEGRATIONS_JSON = JSON.dump(CONFIG_DICT_WITH_INTEGRATIONS)
19411941

19421942
CONFIG_BODY_WITH_HOLDOUTS = VALID_CONFIG_BODY.merge({
1943-
'holdouts' => [
1944-
{
1945-
'id' => 'holdout_1',
1946-
'key' => 'global_holdout',
1947-
'status' => 'Running',
1948-
'includedFlags' => [],
1949-
'excludedFlags' => ['553339214']
1950-
},
1951-
{
1952-
'id' => 'holdout_2',
1953-
'key' => 'specific_holdout',
1954-
'status' => 'Running',
1955-
'includedFlags' => ['594089'],
1956-
'excludedFlags' => []
1957-
},
1958-
{
1959-
'id' => 'holdout_3',
1960-
'key' => 'inactive_holdout',
1961-
'status' => 'Inactive',
1962-
'includedFlags' => ['553339214'],
1963-
'excludedFlags' => []
1964-
}
1965-
]
1966-
}).freeze
1943+
'holdouts' => [
1944+
{
1945+
'id' => 'holdout_1',
1946+
'key' => 'global_holdout',
1947+
'status' => 'Running',
1948+
'includedFlags' => [],
1949+
'excludedFlags' => ['553339214']
1950+
},
1951+
{
1952+
'id' => 'holdout_2',
1953+
'key' => 'specific_holdout',
1954+
'status' => 'Running',
1955+
'includedFlags' => ['594089'],
1956+
'excludedFlags' => []
1957+
},
1958+
{
1959+
'id' => 'holdout_3',
1960+
'key' => 'inactive_holdout',
1961+
'status' => 'Inactive',
1962+
'includedFlags' => ['553339214'],
1963+
'excludedFlags' => []
1964+
}
1965+
]
1966+
}).freeze
19671967

19681968
CONFIG_BODY_WITH_HOLDOUTS_JSON = JSON.dump(CONFIG_BODY_WITH_HOLDOUTS).freeze
19691969

0 commit comments

Comments
 (0)