Skip to content

Commit c4ed888

Browse files
feat: update ruby version (#305)
* update supported ruby versions
1 parent 1f3c89b commit c4ed888

38 files changed

+203
-248
lines changed

.github/workflows/lint_markdown.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- name: Set up Ruby
1111
uses: ruby/setup-ruby@v1
1212
with:
13-
ruby-version: '2.6'
13+
ruby-version: '3.1'
1414
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
1515
- name: Install gem
1616
run: |

.github/workflows/ruby.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
uses: optimizely/ruby-sdk/.github/workflows/lint_markdown.yml@master
1212

1313
integration_tests:
14-
uses: optimizely/ruby-sdk/.github/workflows/integration_test.yml@uzair/with-fsc-git-action
14+
uses: optimizely/ruby-sdk/.github/workflows/integration_test.yml@master
1515
secrets:
1616
CI_USER_TOKEN: ${{ secrets.CI_USER_TOKEN }}
1717
TRAVIS_COM_TOKEN: ${{ secrets.TRAVIS_COM_TOKEN }}
@@ -28,7 +28,7 @@ jobs:
2828
runs-on: ubuntu-latest
2929
strategy:
3030
matrix:
31-
ruby: [ '2.3.7', '2.4.4', '2.5.1', '2.6.0' ]
31+
ruby: [ '2.7.0', '3.0.0', '3.1.0' ]
3232
steps:
3333
- uses: actions/checkout@v3
3434
- name: Set up Ruby ${{ matrix.ruby }}

.rubocop.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
inherit_from: .rubocop_todo.yml
22

33
AllCops:
4-
TargetRubyVersion: 2.3
4+
TargetRubyVersion: 2.7
55

66
Layout/SpaceInsideHashLiteralBraces:
77
EnforcedStyle: no_space
@@ -21,7 +21,7 @@ Metrics/ClassLength:
2121
Metrics/CyclomaticComplexity:
2222
Enabled: false
2323

24-
Metrics/LineLength:
24+
Layout/LineLength:
2525
Enabled: false
2626

2727
Metrics/MethodLength:
@@ -49,4 +49,4 @@ Lint/RescueException:
4949
Enabled: true
5050

5151
Layout/EndOfLine:
52-
EnforcedStyle: lf
52+
Enabled: false

.rubocop_todo.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# versions of RuboCop, may require this file to be generated again.
88

99
# Offense count: 1
10-
Lint/HandleExceptions:
10+
Lint/SuppressedException:
1111
Exclude:
1212
- 'Rakefile'
1313

@@ -44,5 +44,5 @@ Style/TrivialAccessors:
4444
# Offense count: 2465
4545
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
4646
# URISchemes: http, https
47-
Metrics/LineLength:
47+
Layout/LineLength:
4848
Max: 215

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Optimizely Ruby SDK Changelog
22

3+
4+
## Unreleased
5+
6+
### Changes:
7+
* Breaking change: Changed official supported versions of Ruby to 2.7, 3.0 and 3.1
8+
39
## 3.10.1
410
February 2, 2022
511

lib/optimizely.rb

+12-27
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ class Project
6363
# @param notification_center - Optional Instance of NotificationCenter.
6464
# @param event_processor - Optional Responds to process.
6565

66-
def initialize(
66+
def initialize( # rubocop:disable Metrics/ParameterLists
6767
datafile = nil,
6868
event_dispatcher = nil,
6969
logger = nil,
7070
error_handler = nil,
71-
skip_json_validation = false,
71+
skip_json_validation = false, # rubocop:disable Style/OptionalBooleanParameter
7272
user_profile_service = nil,
7373
sdk_key = nil,
7474
config_manager = nil,
@@ -146,8 +146,7 @@ def create_user_context(user_id, attributes = nil)
146146
# validate attributes
147147
return nil unless user_inputs_valid?(attributes)
148148

149-
user_context = OptimizelyUserContext.new(self, user_id, attributes)
150-
user_context
149+
OptimizelyUserContext.new(self, user_id, attributes)
151150
end
152151

153152
def decide(user_context, key, decide_options = [])
@@ -219,11 +218,9 @@ def decide(user_context, key, decide_options = [])
219218
decision_source = decision.source
220219
end
221220

222-
unless decide_options.include? OptimizelyDecideOption::DISABLE_DECISION_EVENT
223-
if decision_source == Optimizely::DecisionService::DECISION_SOURCES['FEATURE_TEST'] || config.send_flag_decisions
224-
send_impression(config, experiment, variation_key || '', flag_key, rule_key || '', feature_enabled, decision_source, user_id, attributes)
225-
decision_event_dispatched = true
226-
end
221+
if !decide_options.include?(OptimizelyDecideOption::DISABLE_DECISION_EVENT) && (decision_source == Optimizely::DecisionService::DECISION_SOURCES['FEATURE_TEST'] || config.send_flag_decisions)
222+
send_impression(config, experiment, variation_key || '', flag_key, rule_key || '', feature_enabled, decision_source, user_id, attributes)
223+
decision_event_dispatched = true
227224
end
228225

229226
# Generate all variables map if decide options doesn't include excludeVariables
@@ -610,15 +607,13 @@ def get_feature_variable(feature_flag_key, variable_key, user_id, attributes = n
610607
@logger.log(Logger::ERROR, InvalidProjectConfigError.new('get_feature_variable').message)
611608
return nil
612609
end
613-
variable_value = get_feature_variable_for_type(
610+
get_feature_variable_for_type(
614611
feature_flag_key,
615612
variable_key,
616613
nil,
617614
user_id,
618615
attributes
619616
)
620-
621-
variable_value
622617
end
623618

624619
# Get the String value of the specified variable in the feature flag.
@@ -636,15 +631,13 @@ def get_feature_variable_string(feature_flag_key, variable_key, user_id, attribu
636631
@logger.log(Logger::ERROR, InvalidProjectConfigError.new('get_feature_variable_string').message)
637632
return nil
638633
end
639-
variable_value = get_feature_variable_for_type(
634+
get_feature_variable_for_type(
640635
feature_flag_key,
641636
variable_key,
642637
Optimizely::Helpers::Constants::VARIABLE_TYPES['STRING'],
643638
user_id,
644639
attributes
645640
)
646-
647-
variable_value
648641
end
649642

650643
# Get the Json value of the specified variable in the feature flag in a Dict.
@@ -662,15 +655,13 @@ def get_feature_variable_json(feature_flag_key, variable_key, user_id, attribute
662655
@logger.log(Logger::ERROR, InvalidProjectConfigError.new('get_feature_variable_json').message)
663656
return nil
664657
end
665-
variable_value = get_feature_variable_for_type(
658+
get_feature_variable_for_type(
666659
feature_flag_key,
667660
variable_key,
668661
Optimizely::Helpers::Constants::VARIABLE_TYPES['JSON'],
669662
user_id,
670663
attributes
671664
)
672-
673-
variable_value
674665
end
675666

676667
# Get the Boolean value of the specified variable in the feature flag.
@@ -689,15 +680,13 @@ def get_feature_variable_boolean(feature_flag_key, variable_key, user_id, attrib
689680
return nil
690681
end
691682

692-
variable_value = get_feature_variable_for_type(
683+
get_feature_variable_for_type(
693684
feature_flag_key,
694685
variable_key,
695686
Optimizely::Helpers::Constants::VARIABLE_TYPES['BOOLEAN'],
696687
user_id,
697688
attributes
698689
)
699-
700-
variable_value
701690
end
702691

703692
# Get the Double value of the specified variable in the feature flag.
@@ -716,15 +705,13 @@ def get_feature_variable_double(feature_flag_key, variable_key, user_id, attribu
716705
return nil
717706
end
718707

719-
variable_value = get_feature_variable_for_type(
708+
get_feature_variable_for_type(
720709
feature_flag_key,
721710
variable_key,
722711
Optimizely::Helpers::Constants::VARIABLE_TYPES['DOUBLE'],
723712
user_id,
724713
attributes
725714
)
726-
727-
variable_value
728715
end
729716

730717
# Get values of all the variables in the feature flag and returns them in a Dict
@@ -809,15 +796,13 @@ def get_feature_variable_integer(feature_flag_key, variable_key, user_id, attrib
809796
return nil
810797
end
811798

812-
variable_value = get_feature_variable_for_type(
799+
get_feature_variable_for_type(
813800
feature_flag_key,
814801
variable_key,
815802
Optimizely::Helpers::Constants::VARIABLE_TYPES['INTEGER'],
816803
user_id,
817804
attributes
818805
)
819-
820-
variable_value
821806
end
822807

823808
def is_valid

lib/optimizely/condition_tree_evaluator.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
#
4-
# Copyright 2019, Optimizely and contributors
4+
# Copyright 2019, 2022, Optimizely and contributors
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@ def evaluate(conditions, leaf_evaluator)
4545

4646
if conditions.is_a? Array
4747
first_operator = conditions[0]
48-
rest_of_conditions = conditions[1..-1]
48+
rest_of_conditions = conditions[1..]
4949

5050
# Operator to apply is not explicit - assume 'or'
5151
unless EVALUATORS_BY_OPERATOR_TYPE.include?(conditions[0])

lib/optimizely/config/datafile_project_config.rb

+12-42
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
# Copyright 2019-2021, Optimizely and contributors
3+
# Copyright 2019-2022, 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.
@@ -24,53 +24,23 @@ class DatafileProjectConfig < ProjectConfig
2424
RUNNING_EXPERIMENT_STATUS = ['Running'].freeze
2525
RESERVED_ATTRIBUTE_PREFIX = '$opt_'
2626

27-
attr_reader :datafile
28-
attr_reader :account_id
29-
attr_reader :attributes
30-
attr_reader :audiences
31-
attr_reader :typed_audiences
32-
attr_reader :events
33-
attr_reader :experiments
34-
attr_reader :feature_flags
35-
attr_reader :groups
36-
attr_reader :project_id
27+
attr_reader :datafile, :account_id, :attributes, :audiences, :typed_audiences, :events,
28+
:experiments, :feature_flags, :groups, :project_id, :bot_filtering, :revision,
29+
:sdk_key, :environment_key, :rollouts, :version, :send_flag_decisions,
30+
:attribute_key_map, :audience_id_map, :event_key_map, :experiment_feature_map,
31+
:experiment_id_map, :experiment_key_map, :feature_flag_key_map, :feature_variable_key_map,
32+
:group_id_map, :rollout_id_map, :rollout_experiment_id_map, :variation_id_map,
33+
:variation_id_to_variable_usage_map, :variation_key_map, :variation_id_map_by_experiment_id,
34+
:variation_key_map_by_experiment_id, :flag_variation_map, :integration_key_map, :integrations,
35+
:public_key_for_odp, :host_for_odp, :all_segments
3736
# Boolean - denotes if Optimizely should remove the last block of visitors' IP address before storing event data
3837
attr_reader :anonymize_ip
39-
attr_reader :bot_filtering
40-
attr_reader :revision
41-
attr_reader :sdk_key
42-
attr_reader :environment_key
43-
attr_reader :rollouts
44-
attr_reader :version
45-
attr_reader :send_flag_decisions
46-
attr_reader :integrations
47-
attr_reader :public_key_for_odp
48-
attr_reader :host_for_odp
49-
attr_reader :all_segments
50-
51-
attr_reader :attribute_key_map
52-
attr_reader :audience_id_map
53-
attr_reader :event_key_map
54-
attr_reader :experiment_feature_map
55-
attr_reader :experiment_id_map
56-
attr_reader :experiment_key_map
57-
attr_reader :feature_flag_key_map
58-
attr_reader :feature_variable_key_map
59-
attr_reader :group_id_map
60-
attr_reader :rollout_id_map
61-
attr_reader :rollout_experiment_id_map
62-
attr_reader :variation_id_map
63-
attr_reader :variation_id_to_variable_usage_map
64-
attr_reader :variation_key_map
65-
attr_reader :variation_id_map_by_experiment_id
66-
attr_reader :variation_key_map_by_experiment_id
67-
attr_reader :flag_variation_map
68-
attr_reader :integration_key_map
6938

7039
def initialize(datafile, logger, error_handler)
7140
# ProjectConfig init method to fetch and set project config data
7241
#
7342
# datafile - JSON string representing the project
43+
super()
7444

7545
config = JSON.parse(datafile)
7646

@@ -224,7 +194,7 @@ def self.create(datafile, logger, error_handler, skip_json_validation)
224194
config = new(datafile, logger, error_handler)
225195
rescue StandardError => e
226196
default_logger = SimpleLogger.new
227-
error_to_handle = e.class == InvalidDatafileVersionError ? e : InvalidInputError.new('datafile')
197+
error_to_handle = e.instance_of?(InvalidDatafileVersionError) ? e : InvalidInputError.new('datafile')
228198
error_msg = error_to_handle.message
229199

230200
default_logger.log(Logger::ERROR, error_msg)

lib/optimizely/config_manager/http_project_config_manager.rb

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def initialize(
6969
datafile_access_token: nil,
7070
proxy_config: nil
7171
)
72+
super()
7273
@logger = logger || NoOpLogger.new
7374
@error_handler = error_handler || NoOpErrorHandler.new
7475
@access_token = datafile_access_token

lib/optimizely/config_manager/static_project_config_manager.rb

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def initialize(datafile, logger, error_handler, skip_json_validation)
3434
# skip_json_validation - Optional boolean param which allows skipping JSON schema
3535
# validation upon object invocation. By default JSON schema validation will be performed.
3636
# Returns instance of DatafileProjectConfig, nil otherwise.
37+
super()
3738
@config = DatafileProjectConfig.create(
3839
datafile,
3940
logger,

lib/optimizely/event/batch_event_processor.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
#
4-
# Copyright 2019, Optimizely and contributors
4+
# Copyright 2019, 2022, Optimizely and contributors
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -43,6 +43,7 @@ def initialize(
4343
logger: NoOpLogger.new,
4444
notification_center: nil
4545
)
46+
super()
4647
@event_queue = event_queue
4748
@logger = logger
4849
@event_dispatcher = event_dispatcher || EventDispatcher.new(logger: @logger)
@@ -101,8 +102,8 @@ def process(user_event)
101102
@event_queue.push(user_event, true)
102103
@wait_mutex.synchronize { @resource.signal }
103104
rescue => e
104-
@logger.log(Logger::WARN, 'Payload not accepted by the queue: ' + e.message)
105-
return
105+
@logger.log(Logger::WARN, "Payload not accepted by the queue: #{e.message}")
106+
nil
106107
end
107108
end
108109

lib/optimizely/event/entity/conversion_event.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
#
4-
# Copyright 2019, Optimizely and contributors
4+
# Copyright 2019, 2022, Optimizely and contributors
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@ def initialize(
3030
tags:,
3131
bot_filtering:
3232
)
33+
super()
3334
@event_context = event_context
3435
@uuid = SecureRandom.uuid
3536
@timestamp = Helpers::DateTimeUtils.create_timestamp

lib/optimizely/event/entity/impression_event.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
#
4-
# Copyright 2019-2020, Optimizely and contributors
4+
# Copyright 2019-2020, 2022, Optimizely and contributors
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@ def initialize(
3232
visitor_attributes:,
3333
bot_filtering:
3434
)
35+
super()
3536
@event_context = event_context
3637
@uuid = SecureRandom.uuid
3738
@timestamp = Helpers::DateTimeUtils.create_timestamp

0 commit comments

Comments
 (0)