Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Lint/HandleExceptions:
# Offense count: 1
Lint/LiteralAsCondition:
Exclude:
- 'lib/optimizely/project_config.rb'
- 'lib/optimizely/config/datafile_project_config.rb'

# Offense count: 1
# Configuration parameters: CountKeywordArgs.
Expand Down
10 changes: 5 additions & 5 deletions lib/optimizely.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# limitations under the License.
#
require_relative 'optimizely/audience'
require_relative 'optimizely/config/datafile_project_config'
require_relative 'optimizely/decision_service'
require_relative 'optimizely/error_handler'
require_relative 'optimizely/event_builder'
Expand All @@ -27,7 +28,6 @@
require_relative 'optimizely/helpers/variable_type'
require_relative 'optimizely/logger'
require_relative 'optimizely/notification_center'
require_relative 'optimizely/project_config'

module Optimizely
class Project
Expand Down Expand Up @@ -63,7 +63,7 @@ def initialize(datafile, event_dispatcher = nil, logger = nil, error_handler = n
end

begin
@config = ProjectConfig.new(datafile, @logger, @error_handler)
@config = DatafileProjectConfig.new(datafile, @logger, @error_handler)
rescue StandardError => e
@is_valid = false
@logger = SimpleLogger.new
Expand Down Expand Up @@ -236,12 +236,12 @@ def track(event_key, user_id, attributes = nil, event_tags = nil)

event = @config.get_event_from_key(event_key)
unless event
@config.logger.log(Logger::INFO, "Not tracking user '#{user_id}' for event '#{event_key}'.")
@logger.log(Logger::INFO, "Not tracking user '#{user_id}' for event '#{event_key}'.")
return nil
end

conversion_event = @event_builder.create_conversion_event(@config, event, user_id, attributes, event_tags)
@config.logger.log(Logger::INFO, "Tracking event '#{event_key}' for user '#{user_id}'.")
@logger.log(Logger::INFO, "Tracking event '#{event_key}' for user '#{user_id}'.")
@logger.log(Logger::INFO,
"Dispatching conversion event to URL #{conversion_event.url} with params #{conversion_event.params}.")
begin
Expand Down Expand Up @@ -506,7 +506,7 @@ def get_feature_variable_for_type(feature_flag_key, variable_key, variable_type,

variable = @config.get_feature_variable(feature_flag, variable_key)

# Error message logged in ProjectConfig- get_feature_flag_from_key
# Error message logged in DatafileProjectConfig- get_feature_flag_from_key
return nil if variable.nil?

feature_enabled = false
Expand Down
14 changes: 7 additions & 7 deletions lib/optimizely/audience.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Optimizely
module Audience
module_function

def user_in_experiment?(config, experiment, attributes)
def user_in_experiment?(config, experiment, attributes, logger)
# Determine for given experiment if user satisfies the audiences for the experiment.
#
# config - Representation of the Optimizely project config.
Expand All @@ -36,7 +36,7 @@ def user_in_experiment?(config, experiment, attributes)

audience_conditions = experiment['audienceConditions'] || experiment['audienceIds']

config.logger.log(
logger.log(
Logger::DEBUG,
format(
Helpers::Constants::AUDIENCE_EVALUATION_LOGS['EVALUATING_AUDIENCES_COMBINED'],
Expand All @@ -47,7 +47,7 @@ def user_in_experiment?(config, experiment, attributes)

# Return true if there are no audiences
if audience_conditions.empty?
config.logger.log(
logger.log(
Logger::INFO,
format(
Helpers::Constants::AUDIENCE_EVALUATION_LOGS['AUDIENCE_EVALUATION_RESULT_COMBINED'],
Expand All @@ -60,7 +60,7 @@ def user_in_experiment?(config, experiment, attributes)

attributes ||= {}

custom_attr_condition_evaluator = CustomAttributeConditionEvaluator.new(attributes, config.logger)
custom_attr_condition_evaluator = CustomAttributeConditionEvaluator.new(attributes, logger)

evaluate_custom_attr = lambda do |condition|
return custom_attr_condition_evaluator.evaluate(condition)
Expand All @@ -71,7 +71,7 @@ def user_in_experiment?(config, experiment, attributes)
return nil unless audience

audience_conditions = audience['conditions']
config.logger.log(
logger.log(
Logger::DEBUG,
format(
Helpers::Constants::AUDIENCE_EVALUATION_LOGS['EVALUATING_AUDIENCE'],
Expand All @@ -83,7 +83,7 @@ def user_in_experiment?(config, experiment, attributes)
audience_conditions = JSON.parse(audience_conditions) if audience_conditions.is_a?(String)
result = ConditionTreeEvaluator.evaluate(audience_conditions, evaluate_custom_attr)
result_str = result.nil? ? 'UNKNOWN' : result.to_s.upcase
config.logger.log(
logger.log(
Logger::INFO,
format(Helpers::Constants::AUDIENCE_EVALUATION_LOGS['AUDIENCE_EVALUATION_RESULT'], audience_id, result_str)
)
Expand All @@ -94,7 +94,7 @@ def user_in_experiment?(config, experiment, attributes)

eval_result ||= false

config.logger.log(
logger.log(
Logger::INFO,
format(
Helpers::Constants::AUDIENCE_EVALUATION_LOGS['AUDIENCE_EVALUATION_RESULT_COMBINED'],
Expand Down
2 changes: 1 addition & 1 deletion lib/optimizely/bucketer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def bucket(project_config, experiment, bucketing_id, user_id)
experiment_key = experiment['key']
group_id = experiment['groupId']
if group_id
group = project_config.group_key_map.fetch(group_id)
group = project_config.group_id_map.fetch(group_id)
if Helpers::Group.random_policy?(group)
traffic_allocations = group.fetch('trafficAllocation')
bucketed_experiment_id = find_bucket(bucketing_id, user_id, group_id, traffic_allocations)
Expand Down
Loading