optimizely-sdk 3.10.1 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +202 -202
- data/lib/optimizely/audience.rb +127 -97
- data/lib/optimizely/bucketer.rb +156 -156
- data/lib/optimizely/condition_tree_evaluator.rb +123 -123
- data/lib/optimizely/config/datafile_project_config.rb +539 -552
- 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 +330 -329
- data/lib/optimizely/config_manager/project_config_manager.rb +24 -24
- data/lib/optimizely/config_manager/static_project_config_manager.rb +53 -52
- 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 +563 -563
- data/lib/optimizely/error_handler.rb +39 -39
- data/lib/optimizely/event/batch_event_processor.rb +235 -234
- data/lib/optimizely/event/entity/conversion_event.rb +44 -43
- 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 -47
- 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 -35
- data/lib/optimizely/event/entity/visitor_attribute.rb +38 -37
- data/lib/optimizely/event/event_factory.rb +156 -155
- data/lib/optimizely/event/event_processor.rb +25 -25
- data/lib/optimizely/event/forwarding_event_processor.rb +44 -43
- data/lib/optimizely/event/user_event_factory.rb +88 -88
- data/lib/optimizely/event_builder.rb +221 -228
- data/lib/optimizely/event_dispatcher.rb +71 -71
- data/lib/optimizely/exceptions.rb +135 -139
- data/lib/optimizely/helpers/constants.rb +415 -397
- 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 +65 -64
- data/lib/optimizely/helpers/validator.rb +183 -183
- data/lib/optimizely/helpers/variable_type.rb +67 -67
- data/lib/optimizely/logger.rb +46 -45
- data/lib/optimizely/notification_center.rb +174 -176
- data/lib/optimizely/optimizely_config.rb +271 -272
- data/lib/optimizely/optimizely_factory.rb +181 -181
- data/lib/optimizely/optimizely_user_context.rb +204 -179
- data/lib/optimizely/params.rb +31 -31
- data/lib/optimizely/project_config.rb +99 -91
- data/lib/optimizely/semantic_version.rb +166 -166
- data/lib/optimizely/{custom_attribute_condition_evaluator.rb → user_condition_evaluator.rb} +391 -369
- data/lib/optimizely/user_profile_service.rb +35 -35
- data/lib/optimizely/version.rb +21 -21
- data/lib/optimizely.rb +1130 -1145
- metadata +13 -13
@@ -1,166 +1,166 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#
|
4
|
-
# Copyright 2020, 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
|
-
|
19
|
-
require_relative 'exceptions'
|
20
|
-
|
21
|
-
module Optimizely
|
22
|
-
module SemanticVersion
|
23
|
-
# Semantic Version Operators
|
24
|
-
SEMVER_PRE_RELEASE = '-'
|
25
|
-
SEMVER_BUILD = '+'
|
26
|
-
|
27
|
-
module_function
|
28
|
-
|
29
|
-
def pre_release?(target)
|
30
|
-
# Method to check if the given version is a prerelease
|
31
|
-
#
|
32
|
-
# target - String representing semantic version
|
33
|
-
#
|
34
|
-
# Returns true if the given version is a prerelease
|
35
|
-
# false if it doesn't
|
36
|
-
|
37
|
-
raise unless target.is_a? String
|
38
|
-
|
39
|
-
prerelease_index = target.index(SEMVER_PRE_RELEASE)
|
40
|
-
build_index = target.index(SEMVER_BUILD)
|
41
|
-
|
42
|
-
return false if prerelease_index.nil?
|
43
|
-
return true if build_index.nil?
|
44
|
-
|
45
|
-
# when both operators are present prerelease should precede the build operator
|
46
|
-
prerelease_index < build_index
|
47
|
-
end
|
48
|
-
|
49
|
-
def build?(target)
|
50
|
-
# Method to check if the given version is a build
|
51
|
-
#
|
52
|
-
# target - String representing semantic version
|
53
|
-
#
|
54
|
-
# Returns true if the given version is a build
|
55
|
-
# false if it doesn't
|
56
|
-
|
57
|
-
raise unless target.is_a? String
|
58
|
-
|
59
|
-
prerelease_index = target.index(SEMVER_PRE_RELEASE)
|
60
|
-
build_index = target.index(SEMVER_BUILD)
|
61
|
-
|
62
|
-
return false if build_index.nil?
|
63
|
-
return true if prerelease_index.nil?
|
64
|
-
|
65
|
-
# when both operators are present build should precede the prerelease operator
|
66
|
-
build_index < prerelease_index
|
67
|
-
end
|
68
|
-
|
69
|
-
def split_semantic_version(target)
|
70
|
-
# Method to split the given version.
|
71
|
-
#
|
72
|
-
# target - String representing semantic version
|
73
|
-
#
|
74
|
-
# Returns List The array of version split into smaller parts i.e major, minor, patch etc,
|
75
|
-
# Exception if the given version is invalid.
|
76
|
-
|
77
|
-
target_prefix = target
|
78
|
-
target_suffix = ''
|
79
|
-
target_parts = []
|
80
|
-
|
81
|
-
raise InvalidSemanticVersion if target.include? ' '
|
82
|
-
|
83
|
-
if pre_release?(target)
|
84
|
-
target_parts = target.split(SEMVER_PRE_RELEASE, 2)
|
85
|
-
elsif build? target
|
86
|
-
target_parts = target.split(SEMVER_BUILD, 2)
|
87
|
-
end
|
88
|
-
|
89
|
-
unless target_parts.empty?
|
90
|
-
target_prefix = target_parts[0].to_s
|
91
|
-
target_suffix = target_parts[1
|
92
|
-
end
|
93
|
-
|
94
|
-
# expect a version string of the form x.y.z
|
95
|
-
dot_count = target_prefix.count('.')
|
96
|
-
raise InvalidSemanticVersion if dot_count > 2
|
97
|
-
|
98
|
-
target_version_parts = target_prefix.split('.')
|
99
|
-
raise InvalidSemanticVersion if target_version_parts.length != dot_count + 1
|
100
|
-
|
101
|
-
target_version_parts.each do |part|
|
102
|
-
raise InvalidSemanticVersion unless Helpers::Validator.string_numeric? part
|
103
|
-
end
|
104
|
-
|
105
|
-
target_version_parts.concat(target_suffix) if target_suffix.is_a?(Array)
|
106
|
-
|
107
|
-
target_version_parts
|
108
|
-
end
|
109
|
-
|
110
|
-
def compare_user_version_with_target_version(target_version, user_version)
|
111
|
-
# Compares target and user versions
|
112
|
-
#
|
113
|
-
# target_version - String representing target version
|
114
|
-
# user_version - String representing user version
|
115
|
-
|
116
|
-
# Returns boolean 0 if user version is equal to target version,
|
117
|
-
# 1 if user version is greater than target version,
|
118
|
-
# -1 if user version is less than target version.
|
119
|
-
|
120
|
-
raise InvalidAttributeType unless target_version.is_a? String
|
121
|
-
raise InvalidAttributeType unless user_version.is_a? String
|
122
|
-
|
123
|
-
is_target_version_prerelease = pre_release?(target_version)
|
124
|
-
is_user_version_prerelease = pre_release?(user_version)
|
125
|
-
|
126
|
-
target_version_parts = split_semantic_version(target_version)
|
127
|
-
user_version_parts = split_semantic_version(user_version)
|
128
|
-
user_version_parts_len = user_version_parts.length if user_version_parts
|
129
|
-
|
130
|
-
# Up to the precision of targetedVersion, expect version to match exactly.
|
131
|
-
target_version_parts.each_with_index do |_item, idx|
|
132
|
-
if user_version_parts_len <= idx
|
133
|
-
# even if they are equal at this point. if the target is a prerelease
|
134
|
-
# then user version must be greater than the pre release.
|
135
|
-
return 1 if is_target_version_prerelease
|
136
|
-
|
137
|
-
return -1
|
138
|
-
|
139
|
-
elsif !Helpers::Validator.string_numeric? user_version_parts[idx]
|
140
|
-
# compare strings
|
141
|
-
if user_version_parts[idx] < target_version_parts[idx]
|
142
|
-
return 1 if is_target_version_prerelease && !is_user_version_prerelease
|
143
|
-
|
144
|
-
return -1
|
145
|
-
|
146
|
-
elsif user_version_parts[idx] > target_version_parts[idx]
|
147
|
-
return -1 if is_user_version_prerelease && !is_target_version_prerelease
|
148
|
-
|
149
|
-
return 1
|
150
|
-
end
|
151
|
-
|
152
|
-
else
|
153
|
-
user_version_part = user_version_parts[idx].to_i
|
154
|
-
target_version_part = target_version_parts[idx].to_i
|
155
|
-
|
156
|
-
return 1 if user_version_part > target_version_part
|
157
|
-
return -1 if user_version_part < target_version_part
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
return -1 if is_user_version_prerelease && !is_target_version_prerelease
|
162
|
-
|
163
|
-
0
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright 2020, 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
|
+
|
19
|
+
require_relative 'exceptions'
|
20
|
+
|
21
|
+
module Optimizely
|
22
|
+
module SemanticVersion
|
23
|
+
# Semantic Version Operators
|
24
|
+
SEMVER_PRE_RELEASE = '-'
|
25
|
+
SEMVER_BUILD = '+'
|
26
|
+
|
27
|
+
module_function
|
28
|
+
|
29
|
+
def pre_release?(target)
|
30
|
+
# Method to check if the given version is a prerelease
|
31
|
+
#
|
32
|
+
# target - String representing semantic version
|
33
|
+
#
|
34
|
+
# Returns true if the given version is a prerelease
|
35
|
+
# false if it doesn't
|
36
|
+
|
37
|
+
raise unless target.is_a? String
|
38
|
+
|
39
|
+
prerelease_index = target.index(SEMVER_PRE_RELEASE)
|
40
|
+
build_index = target.index(SEMVER_BUILD)
|
41
|
+
|
42
|
+
return false if prerelease_index.nil?
|
43
|
+
return true if build_index.nil?
|
44
|
+
|
45
|
+
# when both operators are present prerelease should precede the build operator
|
46
|
+
prerelease_index < build_index
|
47
|
+
end
|
48
|
+
|
49
|
+
def build?(target)
|
50
|
+
# Method to check if the given version is a build
|
51
|
+
#
|
52
|
+
# target - String representing semantic version
|
53
|
+
#
|
54
|
+
# Returns true if the given version is a build
|
55
|
+
# false if it doesn't
|
56
|
+
|
57
|
+
raise unless target.is_a? String
|
58
|
+
|
59
|
+
prerelease_index = target.index(SEMVER_PRE_RELEASE)
|
60
|
+
build_index = target.index(SEMVER_BUILD)
|
61
|
+
|
62
|
+
return false if build_index.nil?
|
63
|
+
return true if prerelease_index.nil?
|
64
|
+
|
65
|
+
# when both operators are present build should precede the prerelease operator
|
66
|
+
build_index < prerelease_index
|
67
|
+
end
|
68
|
+
|
69
|
+
def split_semantic_version(target)
|
70
|
+
# Method to split the given version.
|
71
|
+
#
|
72
|
+
# target - String representing semantic version
|
73
|
+
#
|
74
|
+
# Returns List The array of version split into smaller parts i.e major, minor, patch etc,
|
75
|
+
# Exception if the given version is invalid.
|
76
|
+
|
77
|
+
target_prefix = target
|
78
|
+
target_suffix = ''
|
79
|
+
target_parts = []
|
80
|
+
|
81
|
+
raise InvalidSemanticVersion if target.include? ' '
|
82
|
+
|
83
|
+
if pre_release?(target)
|
84
|
+
target_parts = target.split(SEMVER_PRE_RELEASE, 2)
|
85
|
+
elsif build? target
|
86
|
+
target_parts = target.split(SEMVER_BUILD, 2)
|
87
|
+
end
|
88
|
+
|
89
|
+
unless target_parts.empty?
|
90
|
+
target_prefix = target_parts[0].to_s
|
91
|
+
target_suffix = target_parts[1..]
|
92
|
+
end
|
93
|
+
|
94
|
+
# expect a version string of the form x.y.z
|
95
|
+
dot_count = target_prefix.count('.')
|
96
|
+
raise InvalidSemanticVersion if dot_count > 2
|
97
|
+
|
98
|
+
target_version_parts = target_prefix.split('.')
|
99
|
+
raise InvalidSemanticVersion if target_version_parts.length != dot_count + 1
|
100
|
+
|
101
|
+
target_version_parts.each do |part|
|
102
|
+
raise InvalidSemanticVersion unless Helpers::Validator.string_numeric? part
|
103
|
+
end
|
104
|
+
|
105
|
+
target_version_parts.concat(target_suffix) if target_suffix.is_a?(Array)
|
106
|
+
|
107
|
+
target_version_parts
|
108
|
+
end
|
109
|
+
|
110
|
+
def compare_user_version_with_target_version(target_version, user_version)
|
111
|
+
# Compares target and user versions
|
112
|
+
#
|
113
|
+
# target_version - String representing target version
|
114
|
+
# user_version - String representing user version
|
115
|
+
|
116
|
+
# Returns boolean 0 if user version is equal to target version,
|
117
|
+
# 1 if user version is greater than target version,
|
118
|
+
# -1 if user version is less than target version.
|
119
|
+
|
120
|
+
raise InvalidAttributeType unless target_version.is_a? String
|
121
|
+
raise InvalidAttributeType unless user_version.is_a? String
|
122
|
+
|
123
|
+
is_target_version_prerelease = pre_release?(target_version)
|
124
|
+
is_user_version_prerelease = pre_release?(user_version)
|
125
|
+
|
126
|
+
target_version_parts = split_semantic_version(target_version)
|
127
|
+
user_version_parts = split_semantic_version(user_version)
|
128
|
+
user_version_parts_len = user_version_parts.length if user_version_parts
|
129
|
+
|
130
|
+
# Up to the precision of targetedVersion, expect version to match exactly.
|
131
|
+
target_version_parts.each_with_index do |_item, idx|
|
132
|
+
if user_version_parts_len <= idx
|
133
|
+
# even if they are equal at this point. if the target is a prerelease
|
134
|
+
# then user version must be greater than the pre release.
|
135
|
+
return 1 if is_target_version_prerelease
|
136
|
+
|
137
|
+
return -1
|
138
|
+
|
139
|
+
elsif !Helpers::Validator.string_numeric? user_version_parts[idx]
|
140
|
+
# compare strings
|
141
|
+
if user_version_parts[idx] < target_version_parts[idx]
|
142
|
+
return 1 if is_target_version_prerelease && !is_user_version_prerelease
|
143
|
+
|
144
|
+
return -1
|
145
|
+
|
146
|
+
elsif user_version_parts[idx] > target_version_parts[idx]
|
147
|
+
return -1 if is_user_version_prerelease && !is_target_version_prerelease
|
148
|
+
|
149
|
+
return 1
|
150
|
+
end
|
151
|
+
|
152
|
+
else
|
153
|
+
user_version_part = user_version_parts[idx].to_i
|
154
|
+
target_version_part = target_version_parts[idx].to_i
|
155
|
+
|
156
|
+
return 1 if user_version_part > target_version_part
|
157
|
+
return -1 if user_version_part < target_version_part
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
return -1 if is_user_version_prerelease && !is_target_version_prerelease
|
162
|
+
|
163
|
+
0
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|