optimizely-sdk 3.9.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +202 -202
  3. data/lib/optimizely/audience.rb +127 -97
  4. data/lib/optimizely/bucketer.rb +156 -156
  5. data/lib/optimizely/condition_tree_evaluator.rb +123 -123
  6. data/lib/optimizely/config/datafile_project_config.rb +539 -508
  7. data/lib/optimizely/config/proxy_config.rb +34 -34
  8. data/lib/optimizely/config_manager/async_scheduler.rb +95 -95
  9. data/lib/optimizely/config_manager/http_project_config_manager.rb +330 -321
  10. data/lib/optimizely/config_manager/project_config_manager.rb +24 -24
  11. data/lib/optimizely/config_manager/static_project_config_manager.rb +53 -47
  12. data/lib/optimizely/decide/optimizely_decide_option.rb +28 -28
  13. data/lib/optimizely/decide/optimizely_decision.rb +60 -60
  14. data/lib/optimizely/decide/optimizely_decision_message.rb +26 -26
  15. data/lib/optimizely/decision_service.rb +563 -500
  16. data/lib/optimizely/error_handler.rb +39 -39
  17. data/lib/optimizely/event/batch_event_processor.rb +235 -234
  18. data/lib/optimizely/event/entity/conversion_event.rb +44 -43
  19. data/lib/optimizely/event/entity/decision.rb +38 -38
  20. data/lib/optimizely/event/entity/event_batch.rb +86 -86
  21. data/lib/optimizely/event/entity/event_context.rb +50 -50
  22. data/lib/optimizely/event/entity/impression_event.rb +48 -47
  23. data/lib/optimizely/event/entity/snapshot.rb +33 -33
  24. data/lib/optimizely/event/entity/snapshot_event.rb +48 -48
  25. data/lib/optimizely/event/entity/user_event.rb +22 -22
  26. data/lib/optimizely/event/entity/visitor.rb +36 -35
  27. data/lib/optimizely/event/entity/visitor_attribute.rb +38 -37
  28. data/lib/optimizely/event/event_factory.rb +156 -155
  29. data/lib/optimizely/event/event_processor.rb +25 -25
  30. data/lib/optimizely/event/forwarding_event_processor.rb +44 -43
  31. data/lib/optimizely/event/user_event_factory.rb +88 -88
  32. data/lib/optimizely/event_builder.rb +221 -228
  33. data/lib/optimizely/event_dispatcher.rb +71 -71
  34. data/lib/optimizely/exceptions.rb +135 -139
  35. data/lib/optimizely/helpers/constants.rb +415 -397
  36. data/lib/optimizely/helpers/date_time_utils.rb +30 -30
  37. data/lib/optimizely/helpers/event_tag_utils.rb +132 -132
  38. data/lib/optimizely/helpers/group.rb +31 -31
  39. data/lib/optimizely/helpers/http_utils.rb +65 -64
  40. data/lib/optimizely/helpers/validator.rb +183 -183
  41. data/lib/optimizely/helpers/variable_type.rb +67 -67
  42. data/lib/optimizely/logger.rb +46 -45
  43. data/lib/optimizely/notification_center.rb +174 -176
  44. data/lib/optimizely/optimizely_config.rb +271 -272
  45. data/lib/optimizely/optimizely_factory.rb +181 -181
  46. data/lib/optimizely/optimizely_user_context.rb +204 -107
  47. data/lib/optimizely/params.rb +31 -31
  48. data/lib/optimizely/project_config.rb +99 -91
  49. data/lib/optimizely/semantic_version.rb +166 -166
  50. data/lib/optimizely/{custom_attribute_condition_evaluator.rb → user_condition_evaluator.rb} +391 -369
  51. data/lib/optimizely/user_profile_service.rb +35 -35
  52. data/lib/optimizely/version.rb +21 -21
  53. data/lib/optimizely.rb +1130 -1117
  54. 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..-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