optimizely-sdk 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +202 -202
- data/lib/optimizely/audience.rb +127 -127
- data/lib/optimizely/bucketer.rb +156 -156
- data/lib/optimizely/condition_tree_evaluator.rb +123 -123
- data/lib/optimizely/config/datafile_project_config.rb +558 -558
- data/lib/optimizely/config/proxy_config.rb +34 -34
- data/lib/optimizely/config_manager/async_scheduler.rb +95 -95
- data/lib/optimizely/config_manager/http_project_config_manager.rb +340 -340
- data/lib/optimizely/config_manager/project_config_manager.rb +25 -25
- data/lib/optimizely/config_manager/static_project_config_manager.rb +55 -55
- data/lib/optimizely/decide/optimizely_decide_option.rb +28 -28
- data/lib/optimizely/decide/optimizely_decision.rb +60 -60
- data/lib/optimizely/decide/optimizely_decision_message.rb +26 -26
- data/lib/optimizely/decision_service.rb +589 -563
- data/lib/optimizely/error_handler.rb +39 -39
- data/lib/optimizely/event/batch_event_processor.rb +235 -235
- data/lib/optimizely/event/entity/conversion_event.rb +44 -44
- data/lib/optimizely/event/entity/decision.rb +38 -38
- data/lib/optimizely/event/entity/event_batch.rb +86 -86
- data/lib/optimizely/event/entity/event_context.rb +50 -50
- data/lib/optimizely/event/entity/impression_event.rb +48 -48
- data/lib/optimizely/event/entity/snapshot.rb +33 -33
- data/lib/optimizely/event/entity/snapshot_event.rb +48 -48
- data/lib/optimizely/event/entity/user_event.rb +22 -22
- data/lib/optimizely/event/entity/visitor.rb +36 -36
- data/lib/optimizely/event/entity/visitor_attribute.rb +38 -38
- data/lib/optimizely/event/event_factory.rb +156 -156
- data/lib/optimizely/event/event_processor.rb +25 -25
- data/lib/optimizely/event/forwarding_event_processor.rb +44 -44
- data/lib/optimizely/event/user_event_factory.rb +88 -88
- data/lib/optimizely/event_builder.rb +221 -221
- data/lib/optimizely/event_dispatcher.rb +69 -69
- data/lib/optimizely/exceptions.rb +193 -193
- data/lib/optimizely/helpers/constants.rb +459 -459
- data/lib/optimizely/helpers/date_time_utils.rb +30 -30
- data/lib/optimizely/helpers/event_tag_utils.rb +132 -132
- data/lib/optimizely/helpers/group.rb +31 -31
- data/lib/optimizely/helpers/http_utils.rb +68 -68
- data/lib/optimizely/helpers/sdk_settings.rb +61 -61
- data/lib/optimizely/helpers/validator.rb +236 -236
- data/lib/optimizely/helpers/variable_type.rb +67 -67
- data/lib/optimizely/logger.rb +46 -46
- data/lib/optimizely/notification_center.rb +174 -174
- data/lib/optimizely/notification_center_registry.rb +71 -71
- data/lib/optimizely/odp/lru_cache.rb +114 -114
- data/lib/optimizely/odp/odp_config.rb +102 -102
- data/lib/optimizely/odp/odp_event.rb +75 -75
- data/lib/optimizely/odp/odp_event_api_manager.rb +70 -70
- data/lib/optimizely/odp/odp_event_manager.rb +286 -286
- data/lib/optimizely/odp/odp_manager.rb +159 -159
- data/lib/optimizely/odp/odp_segment_api_manager.rb +122 -122
- data/lib/optimizely/odp/odp_segment_manager.rb +97 -97
- data/lib/optimizely/optimizely_config.rb +273 -273
- data/lib/optimizely/optimizely_factory.rb +183 -184
- data/lib/optimizely/optimizely_user_context.rb +238 -238
- data/lib/optimizely/params.rb +31 -31
- data/lib/optimizely/project_config.rb +99 -99
- data/lib/optimizely/semantic_version.rb +166 -166
- data/lib/optimizely/user_condition_evaluator.rb +391 -391
- data/lib/optimizely/user_profile_service.rb +35 -35
- data/lib/optimizely/user_profile_tracker.rb +64 -0
- data/lib/optimizely/version.rb +21 -21
- data/lib/optimizely.rb +1326 -1262
- metadata +8 -5
@@ -1,123 +1,123 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#
|
4
|
-
# Copyright 2019, 2022, Optimizely and contributors
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
module Optimizely
|
19
|
-
module ConditionTreeEvaluator
|
20
|
-
# Operator types
|
21
|
-
AND_CONDITION = 'and'
|
22
|
-
OR_CONDITION = 'or'
|
23
|
-
NOT_CONDITION = 'not'
|
24
|
-
|
25
|
-
EVALUATORS_BY_OPERATOR_TYPE = {
|
26
|
-
AND_CONDITION => :and_evaluator,
|
27
|
-
OR_CONDITION => :or_evaluator,
|
28
|
-
NOT_CONDITION => :not_evaluator
|
29
|
-
}.freeze
|
30
|
-
|
31
|
-
OPERATORS = [AND_CONDITION, OR_CONDITION, NOT_CONDITION].freeze
|
32
|
-
|
33
|
-
module_function
|
34
|
-
|
35
|
-
def evaluate(conditions, leaf_evaluator)
|
36
|
-
# Top level method to evaluate audience conditions.
|
37
|
-
#
|
38
|
-
# conditions - Nested array of and/or conditions.
|
39
|
-
# Example: ['and', operand_1, ['or', operand_2, operand_3]]
|
40
|
-
#
|
41
|
-
# leaf_evaluator - Function which will be called to evaluate leaf condition values.
|
42
|
-
#
|
43
|
-
# Returns boolean if the given user attributes match/don't match the given conditions,
|
44
|
-
# nil if the given conditions are invalid or can't be evaluated.
|
45
|
-
|
46
|
-
if conditions.is_a? Array
|
47
|
-
first_operator = conditions[0]
|
48
|
-
rest_of_conditions = conditions[1..]
|
49
|
-
|
50
|
-
# Operator to apply is not explicit - assume 'or'
|
51
|
-
unless EVALUATORS_BY_OPERATOR_TYPE.include?(conditions[0])
|
52
|
-
first_operator = OR_CONDITION
|
53
|
-
rest_of_conditions = conditions
|
54
|
-
end
|
55
|
-
|
56
|
-
return send(EVALUATORS_BY_OPERATOR_TYPE[first_operator], rest_of_conditions, leaf_evaluator)
|
57
|
-
end
|
58
|
-
|
59
|
-
leaf_evaluator.call(conditions)
|
60
|
-
end
|
61
|
-
|
62
|
-
def and_evaluator(conditions, leaf_evaluator)
|
63
|
-
# Evaluates an array of conditions as if the evaluator had been applied
|
64
|
-
# to each entry and the results AND-ed together.
|
65
|
-
#
|
66
|
-
# conditions - Array of conditions ex: [operand_1, operand_2]
|
67
|
-
#
|
68
|
-
# leaf_evaluator - Function which will be called to evaluate leaf condition values.
|
69
|
-
#
|
70
|
-
# Returns boolean if the user attributes match/don't match the given conditions,
|
71
|
-
# nil if the user attributes and conditions can't be evaluated.
|
72
|
-
|
73
|
-
found_nil = false
|
74
|
-
conditions.each do |condition|
|
75
|
-
result = evaluate(condition, leaf_evaluator)
|
76
|
-
return result if result == false
|
77
|
-
|
78
|
-
found_nil = true if result.nil?
|
79
|
-
end
|
80
|
-
|
81
|
-
found_nil ? nil : true
|
82
|
-
end
|
83
|
-
|
84
|
-
def not_evaluator(single_condition, leaf_evaluator)
|
85
|
-
# Evaluates an array of conditions as if the evaluator had been applied
|
86
|
-
# to a single entry and NOT was applied to the result.
|
87
|
-
#
|
88
|
-
# single_condition - Array of a single condition ex: [operand_1]
|
89
|
-
#
|
90
|
-
# leaf_evaluator - Function which will be called to evaluate leaf condition values.
|
91
|
-
#
|
92
|
-
# Returns boolean if the user attributes match/don't match the given conditions,
|
93
|
-
# nil if the user attributes and conditions can't be evaluated.
|
94
|
-
|
95
|
-
return nil if single_condition.empty?
|
96
|
-
|
97
|
-
result = evaluate(single_condition[0], leaf_evaluator)
|
98
|
-
result.nil? ? nil : !result
|
99
|
-
end
|
100
|
-
|
101
|
-
def or_evaluator(conditions, leaf_evaluator)
|
102
|
-
# Evaluates an array of conditions as if the evaluator had been applied
|
103
|
-
# to each entry and the results OR-ed together.
|
104
|
-
#
|
105
|
-
# conditions - Array of conditions ex: [operand_1, operand_2]
|
106
|
-
#
|
107
|
-
# leaf_evaluator - Function which will be called to evaluate leaf condition values.
|
108
|
-
#
|
109
|
-
# Returns boolean if the user attributes match/don't match the given conditions,
|
110
|
-
# nil if the user attributes and conditions can't be evaluated.
|
111
|
-
|
112
|
-
found_nil = false
|
113
|
-
conditions.each do |condition|
|
114
|
-
result = evaluate(condition, leaf_evaluator)
|
115
|
-
return result if result == true
|
116
|
-
|
117
|
-
found_nil = true if result.nil?
|
118
|
-
end
|
119
|
-
|
120
|
-
found_nil ? nil : false
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright 2019, 2022, Optimizely and contributors
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module Optimizely
|
19
|
+
module ConditionTreeEvaluator
|
20
|
+
# Operator types
|
21
|
+
AND_CONDITION = 'and'
|
22
|
+
OR_CONDITION = 'or'
|
23
|
+
NOT_CONDITION = 'not'
|
24
|
+
|
25
|
+
EVALUATORS_BY_OPERATOR_TYPE = {
|
26
|
+
AND_CONDITION => :and_evaluator,
|
27
|
+
OR_CONDITION => :or_evaluator,
|
28
|
+
NOT_CONDITION => :not_evaluator
|
29
|
+
}.freeze
|
30
|
+
|
31
|
+
OPERATORS = [AND_CONDITION, OR_CONDITION, NOT_CONDITION].freeze
|
32
|
+
|
33
|
+
module_function
|
34
|
+
|
35
|
+
def evaluate(conditions, leaf_evaluator)
|
36
|
+
# Top level method to evaluate audience conditions.
|
37
|
+
#
|
38
|
+
# conditions - Nested array of and/or conditions.
|
39
|
+
# Example: ['and', operand_1, ['or', operand_2, operand_3]]
|
40
|
+
#
|
41
|
+
# leaf_evaluator - Function which will be called to evaluate leaf condition values.
|
42
|
+
#
|
43
|
+
# Returns boolean if the given user attributes match/don't match the given conditions,
|
44
|
+
# nil if the given conditions are invalid or can't be evaluated.
|
45
|
+
|
46
|
+
if conditions.is_a? Array
|
47
|
+
first_operator = conditions[0]
|
48
|
+
rest_of_conditions = conditions[1..]
|
49
|
+
|
50
|
+
# Operator to apply is not explicit - assume 'or'
|
51
|
+
unless EVALUATORS_BY_OPERATOR_TYPE.include?(conditions[0])
|
52
|
+
first_operator = OR_CONDITION
|
53
|
+
rest_of_conditions = conditions
|
54
|
+
end
|
55
|
+
|
56
|
+
return send(EVALUATORS_BY_OPERATOR_TYPE[first_operator], rest_of_conditions, leaf_evaluator)
|
57
|
+
end
|
58
|
+
|
59
|
+
leaf_evaluator.call(conditions)
|
60
|
+
end
|
61
|
+
|
62
|
+
def and_evaluator(conditions, leaf_evaluator)
|
63
|
+
# Evaluates an array of conditions as if the evaluator had been applied
|
64
|
+
# to each entry and the results AND-ed together.
|
65
|
+
#
|
66
|
+
# conditions - Array of conditions ex: [operand_1, operand_2]
|
67
|
+
#
|
68
|
+
# leaf_evaluator - Function which will be called to evaluate leaf condition values.
|
69
|
+
#
|
70
|
+
# Returns boolean if the user attributes match/don't match the given conditions,
|
71
|
+
# nil if the user attributes and conditions can't be evaluated.
|
72
|
+
|
73
|
+
found_nil = false
|
74
|
+
conditions.each do |condition|
|
75
|
+
result = evaluate(condition, leaf_evaluator)
|
76
|
+
return result if result == false
|
77
|
+
|
78
|
+
found_nil = true if result.nil?
|
79
|
+
end
|
80
|
+
|
81
|
+
found_nil ? nil : true
|
82
|
+
end
|
83
|
+
|
84
|
+
def not_evaluator(single_condition, leaf_evaluator)
|
85
|
+
# Evaluates an array of conditions as if the evaluator had been applied
|
86
|
+
# to a single entry and NOT was applied to the result.
|
87
|
+
#
|
88
|
+
# single_condition - Array of a single condition ex: [operand_1]
|
89
|
+
#
|
90
|
+
# leaf_evaluator - Function which will be called to evaluate leaf condition values.
|
91
|
+
#
|
92
|
+
# Returns boolean if the user attributes match/don't match the given conditions,
|
93
|
+
# nil if the user attributes and conditions can't be evaluated.
|
94
|
+
|
95
|
+
return nil if single_condition.empty?
|
96
|
+
|
97
|
+
result = evaluate(single_condition[0], leaf_evaluator)
|
98
|
+
result.nil? ? nil : !result
|
99
|
+
end
|
100
|
+
|
101
|
+
def or_evaluator(conditions, leaf_evaluator)
|
102
|
+
# Evaluates an array of conditions as if the evaluator had been applied
|
103
|
+
# to each entry and the results OR-ed together.
|
104
|
+
#
|
105
|
+
# conditions - Array of conditions ex: [operand_1, operand_2]
|
106
|
+
#
|
107
|
+
# leaf_evaluator - Function which will be called to evaluate leaf condition values.
|
108
|
+
#
|
109
|
+
# Returns boolean if the user attributes match/don't match the given conditions,
|
110
|
+
# nil if the user attributes and conditions can't be evaluated.
|
111
|
+
|
112
|
+
found_nil = false
|
113
|
+
conditions.each do |condition|
|
114
|
+
result = evaluate(condition, leaf_evaluator)
|
115
|
+
return result if result == true
|
116
|
+
|
117
|
+
found_nil = true if result.nil?
|
118
|
+
end
|
119
|
+
|
120
|
+
found_nil ? nil : false
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|