Skip to content

Commit

Permalink
feat: update ruby version (#305)
Browse files Browse the repository at this point in the history
* update supported ruby versions
  • Loading branch information
andrewleap-optimizely authored Aug 4, 2022
1 parent 1f3c89b commit c4ed888
Show file tree
Hide file tree
Showing 38 changed files with 203 additions and 248 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint_markdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '2.6'
ruby-version: '3.1'
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Install gem
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
uses: optimizely/ruby-sdk/.github/workflows/lint_markdown.yml@master

integration_tests:
uses: optimizely/ruby-sdk/.github/workflows/integration_test.yml@uzair/with-fsc-git-action
uses: optimizely/ruby-sdk/.github/workflows/integration_test.yml@master
secrets:
CI_USER_TOKEN: ${{ secrets.CI_USER_TOKEN }}
TRAVIS_COM_TOKEN: ${{ secrets.TRAVIS_COM_TOKEN }}
Expand All @@ -28,7 +28,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: [ '2.3.7', '2.4.4', '2.5.1', '2.6.0' ]
ruby: [ '2.7.0', '3.0.0', '3.1.0' ]
steps:
- uses: actions/checkout@v3
- name: Set up Ruby ${{ matrix.ruby }}
Expand Down
6 changes: 3 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.3
TargetRubyVersion: 2.7

Layout/SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space
Expand All @@ -21,7 +21,7 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Enabled: false

Metrics/LineLength:
Layout/LineLength:
Enabled: false

Metrics/MethodLength:
Expand Down Expand Up @@ -49,4 +49,4 @@ Lint/RescueException:
Enabled: true

Layout/EndOfLine:
EnforcedStyle: lf
Enabled: false
4 changes: 2 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
Lint/HandleExceptions:
Lint/SuppressedException:
Exclude:
- 'Rakefile'

Expand Down Expand Up @@ -44,5 +44,5 @@ Style/TrivialAccessors:
# Offense count: 2465
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Layout/LineLength:
Max: 215
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Optimizely Ruby SDK Changelog


## Unreleased

### Changes:
* Breaking change: Changed official supported versions of Ruby to 2.7, 3.0 and 3.1

## 3.10.1
February 2, 2022

Expand Down
39 changes: 12 additions & 27 deletions lib/optimizely.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ class Project
# @param notification_center - Optional Instance of NotificationCenter.
# @param event_processor - Optional Responds to process.

def initialize(
def initialize( # rubocop:disable Metrics/ParameterLists
datafile = nil,
event_dispatcher = nil,
logger = nil,
error_handler = nil,
skip_json_validation = false,
skip_json_validation = false, # rubocop:disable Style/OptionalBooleanParameter
user_profile_service = nil,
sdk_key = nil,
config_manager = nil,
Expand Down Expand Up @@ -146,8 +146,7 @@ def create_user_context(user_id, attributes = nil)
# validate attributes
return nil unless user_inputs_valid?(attributes)

user_context = OptimizelyUserContext.new(self, user_id, attributes)
user_context
OptimizelyUserContext.new(self, user_id, attributes)
end

def decide(user_context, key, decide_options = [])
Expand Down Expand Up @@ -219,11 +218,9 @@ def decide(user_context, key, decide_options = [])
decision_source = decision.source
end

unless decide_options.include? OptimizelyDecideOption::DISABLE_DECISION_EVENT
if decision_source == Optimizely::DecisionService::DECISION_SOURCES['FEATURE_TEST'] || config.send_flag_decisions
send_impression(config, experiment, variation_key || '', flag_key, rule_key || '', feature_enabled, decision_source, user_id, attributes)
decision_event_dispatched = true
end
if !decide_options.include?(OptimizelyDecideOption::DISABLE_DECISION_EVENT) && (decision_source == Optimizely::DecisionService::DECISION_SOURCES['FEATURE_TEST'] || config.send_flag_decisions)
send_impression(config, experiment, variation_key || '', flag_key, rule_key || '', feature_enabled, decision_source, user_id, attributes)
decision_event_dispatched = true
end

# Generate all variables map if decide options doesn't include excludeVariables
Expand Down Expand Up @@ -610,15 +607,13 @@ def get_feature_variable(feature_flag_key, variable_key, user_id, attributes = n
@logger.log(Logger::ERROR, InvalidProjectConfigError.new('get_feature_variable').message)
return nil
end
variable_value = get_feature_variable_for_type(
get_feature_variable_for_type(
feature_flag_key,
variable_key,
nil,
user_id,
attributes
)

variable_value
end

# Get the String value of the specified variable in the feature flag.
Expand All @@ -636,15 +631,13 @@ def get_feature_variable_string(feature_flag_key, variable_key, user_id, attribu
@logger.log(Logger::ERROR, InvalidProjectConfigError.new('get_feature_variable_string').message)
return nil
end
variable_value = get_feature_variable_for_type(
get_feature_variable_for_type(
feature_flag_key,
variable_key,
Optimizely::Helpers::Constants::VARIABLE_TYPES['STRING'],
user_id,
attributes
)

variable_value
end

# Get the Json value of the specified variable in the feature flag in a Dict.
Expand All @@ -662,15 +655,13 @@ def get_feature_variable_json(feature_flag_key, variable_key, user_id, attribute
@logger.log(Logger::ERROR, InvalidProjectConfigError.new('get_feature_variable_json').message)
return nil
end
variable_value = get_feature_variable_for_type(
get_feature_variable_for_type(
feature_flag_key,
variable_key,
Optimizely::Helpers::Constants::VARIABLE_TYPES['JSON'],
user_id,
attributes
)

variable_value
end

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

variable_value = get_feature_variable_for_type(
get_feature_variable_for_type(
feature_flag_key,
variable_key,
Optimizely::Helpers::Constants::VARIABLE_TYPES['BOOLEAN'],
user_id,
attributes
)

variable_value
end

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

variable_value = get_feature_variable_for_type(
get_feature_variable_for_type(
feature_flag_key,
variable_key,
Optimizely::Helpers::Constants::VARIABLE_TYPES['DOUBLE'],
user_id,
attributes
)

variable_value
end

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

variable_value = get_feature_variable_for_type(
get_feature_variable_for_type(
feature_flag_key,
variable_key,
Optimizely::Helpers::Constants::VARIABLE_TYPES['INTEGER'],
user_id,
attributes
)

variable_value
end

def is_valid
Expand Down
4 changes: 2 additions & 2 deletions lib/optimizely/condition_tree_evaluator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

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

if conditions.is_a? Array
first_operator = conditions[0]
rest_of_conditions = conditions[1..-1]
rest_of_conditions = conditions[1..]

# Operator to apply is not explicit - assume 'or'
unless EVALUATORS_BY_OPERATOR_TYPE.include?(conditions[0])
Expand Down
54 changes: 12 additions & 42 deletions lib/optimizely/config/datafile_project_config.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright 2019-2021, Optimizely and contributors
# Copyright 2019-2022, Optimizely and contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -24,53 +24,23 @@ class DatafileProjectConfig < ProjectConfig
RUNNING_EXPERIMENT_STATUS = ['Running'].freeze
RESERVED_ATTRIBUTE_PREFIX = '$opt_'

attr_reader :datafile
attr_reader :account_id
attr_reader :attributes
attr_reader :audiences
attr_reader :typed_audiences
attr_reader :events
attr_reader :experiments
attr_reader :feature_flags
attr_reader :groups
attr_reader :project_id
attr_reader :datafile, :account_id, :attributes, :audiences, :typed_audiences, :events,
:experiments, :feature_flags, :groups, :project_id, :bot_filtering, :revision,
:sdk_key, :environment_key, :rollouts, :version, :send_flag_decisions,
:attribute_key_map, :audience_id_map, :event_key_map, :experiment_feature_map,
:experiment_id_map, :experiment_key_map, :feature_flag_key_map, :feature_variable_key_map,
:group_id_map, :rollout_id_map, :rollout_experiment_id_map, :variation_id_map,
:variation_id_to_variable_usage_map, :variation_key_map, :variation_id_map_by_experiment_id,
:variation_key_map_by_experiment_id, :flag_variation_map, :integration_key_map, :integrations,
:public_key_for_odp, :host_for_odp, :all_segments
# Boolean - denotes if Optimizely should remove the last block of visitors' IP address before storing event data
attr_reader :anonymize_ip
attr_reader :bot_filtering
attr_reader :revision
attr_reader :sdk_key
attr_reader :environment_key
attr_reader :rollouts
attr_reader :version
attr_reader :send_flag_decisions
attr_reader :integrations
attr_reader :public_key_for_odp
attr_reader :host_for_odp
attr_reader :all_segments

attr_reader :attribute_key_map
attr_reader :audience_id_map
attr_reader :event_key_map
attr_reader :experiment_feature_map
attr_reader :experiment_id_map
attr_reader :experiment_key_map
attr_reader :feature_flag_key_map
attr_reader :feature_variable_key_map
attr_reader :group_id_map
attr_reader :rollout_id_map
attr_reader :rollout_experiment_id_map
attr_reader :variation_id_map
attr_reader :variation_id_to_variable_usage_map
attr_reader :variation_key_map
attr_reader :variation_id_map_by_experiment_id
attr_reader :variation_key_map_by_experiment_id
attr_reader :flag_variation_map
attr_reader :integration_key_map

def initialize(datafile, logger, error_handler)
# ProjectConfig init method to fetch and set project config data
#
# datafile - JSON string representing the project
super()

config = JSON.parse(datafile)

Expand Down Expand Up @@ -224,7 +194,7 @@ def self.create(datafile, logger, error_handler, skip_json_validation)
config = new(datafile, logger, error_handler)
rescue StandardError => e
default_logger = SimpleLogger.new
error_to_handle = e.class == InvalidDatafileVersionError ? e : InvalidInputError.new('datafile')
error_to_handle = e.instance_of?(InvalidDatafileVersionError) ? e : InvalidInputError.new('datafile')
error_msg = error_to_handle.message

default_logger.log(Logger::ERROR, error_msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def initialize(
datafile_access_token: nil,
proxy_config: nil
)
super()
@logger = logger || NoOpLogger.new
@error_handler = error_handler || NoOpErrorHandler.new
@access_token = datafile_access_token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def initialize(datafile, logger, error_handler, skip_json_validation)
# skip_json_validation - Optional boolean param which allows skipping JSON schema
# validation upon object invocation. By default JSON schema validation will be performed.
# Returns instance of DatafileProjectConfig, nil otherwise.
super()
@config = DatafileProjectConfig.create(
datafile,
logger,
Expand Down
7 changes: 4 additions & 3 deletions lib/optimizely/event/batch_event_processor.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

#
# Copyright 2019, Optimizely and contributors
# Copyright 2019, 2022, Optimizely and contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,6 +43,7 @@ def initialize(
logger: NoOpLogger.new,
notification_center: nil
)
super()
@event_queue = event_queue
@logger = logger
@event_dispatcher = event_dispatcher || EventDispatcher.new(logger: @logger)
Expand Down Expand Up @@ -101,8 +102,8 @@ def process(user_event)
@event_queue.push(user_event, true)
@wait_mutex.synchronize { @resource.signal }
rescue => e
@logger.log(Logger::WARN, 'Payload not accepted by the queue: ' + e.message)
return
@logger.log(Logger::WARN, "Payload not accepted by the queue: #{e.message}")
nil
end
end

Expand Down
3 changes: 2 additions & 1 deletion lib/optimizely/event/entity/conversion_event.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

#
# Copyright 2019, Optimizely and contributors
# Copyright 2019, 2022, Optimizely and contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,6 +30,7 @@ def initialize(
tags:,
bot_filtering:
)
super()
@event_context = event_context
@uuid = SecureRandom.uuid
@timestamp = Helpers::DateTimeUtils.create_timestamp
Expand Down
3 changes: 2 additions & 1 deletion lib/optimizely/event/entity/impression_event.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

#
# Copyright 2019-2020, Optimizely and contributors
# Copyright 2019-2020, 2022, Optimizely and contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,6 +32,7 @@ def initialize(
visitor_attributes:,
bot_filtering:
)
super()
@event_context = event_context
@uuid = SecureRandom.uuid
@timestamp = Helpers::DateTimeUtils.create_timestamp
Expand Down
Loading

0 comments on commit c4ed888

Please sign in to comment.