optimizely-sdk 5.0.0.pre.beta → 5.0.1
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 -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 +48 -32
- 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 -338
- data/lib/optimizely/config_manager/project_config_manager.rb +25 -25
- data/lib/optimizely/config_manager/static_project_config_manager.rb +55 -54
- 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 -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 -149
- 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 -238
- 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 -271
- data/lib/optimizely/optimizely_factory.rb +184 -186
- 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/version.rb +21 -21
- data/lib/optimizely.rb +1262 -1262
- metadata +12 -10
@@ -1,99 +1,99 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright 2016-2021, Optimizely and contributors
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
|
-
|
18
|
-
module Optimizely
|
19
|
-
class ProjectConfig
|
20
|
-
# ProjectConfig is an interface capturing the experiment, variation and feature definitions.
|
21
|
-
# The default implementation of ProjectConfig can be found in DatafileProjectConfig.
|
22
|
-
|
23
|
-
def datafile; end
|
24
|
-
|
25
|
-
def account_id; end
|
26
|
-
|
27
|
-
def attributes; end
|
28
|
-
|
29
|
-
def audiences; end
|
30
|
-
|
31
|
-
def typed_audiences; end
|
32
|
-
|
33
|
-
def events; end
|
34
|
-
|
35
|
-
def experiments; end
|
36
|
-
|
37
|
-
def feature_flags; end
|
38
|
-
|
39
|
-
def groups; end
|
40
|
-
|
41
|
-
def project_id; end
|
42
|
-
|
43
|
-
def anonymize_ip; end
|
44
|
-
|
45
|
-
def bot_filtering; end
|
46
|
-
|
47
|
-
def revision; end
|
48
|
-
|
49
|
-
def sdk_key; end
|
50
|
-
|
51
|
-
def environment_key; end
|
52
|
-
|
53
|
-
def send_flag_decisions; end
|
54
|
-
|
55
|
-
def rollouts; end
|
56
|
-
|
57
|
-
def integrations; end
|
58
|
-
|
59
|
-
def public_key_for_odp; end
|
60
|
-
|
61
|
-
def host_for_odp; end
|
62
|
-
|
63
|
-
def all_segments; end
|
64
|
-
|
65
|
-
def experiment_running?(experiment); end
|
66
|
-
|
67
|
-
def get_experiment_from_key(experiment_key); end
|
68
|
-
|
69
|
-
def get_experiment_from_id(experiment_id); end
|
70
|
-
|
71
|
-
def get_experiment_key(experiment_id); end
|
72
|
-
|
73
|
-
def get_event_from_key(event_key); end
|
74
|
-
|
75
|
-
def get_audience_from_id(audience_id); end
|
76
|
-
|
77
|
-
def get_variation_from_id(experiment_key, variation_id); end
|
78
|
-
|
79
|
-
def get_variation_from_id_by_experiment_id(experiment_id, variation_id); end
|
80
|
-
|
81
|
-
def get_variation_id_from_key_by_experiment_id(experiment_id, variation_key); end
|
82
|
-
|
83
|
-
def get_variation_id_from_key(experiment_key, variation_key); end
|
84
|
-
|
85
|
-
def get_whitelisted_variations(experiment_id); end
|
86
|
-
|
87
|
-
def get_attribute_id(attribute_key); end
|
88
|
-
|
89
|
-
def variation_id_exists?(experiment_id, variation_id); end
|
90
|
-
|
91
|
-
def get_feature_flag_from_key(feature_flag_key); end
|
92
|
-
|
93
|
-
def get_feature_variable(feature_flag, variable_key); end
|
94
|
-
|
95
|
-
def get_rollout_from_id(rollout_id); end
|
96
|
-
|
97
|
-
def feature_experiment?(experiment_id); end
|
98
|
-
end
|
99
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016-2021, Optimizely and contributors
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
module Optimizely
|
19
|
+
class ProjectConfig
|
20
|
+
# ProjectConfig is an interface capturing the experiment, variation and feature definitions.
|
21
|
+
# The default implementation of ProjectConfig can be found in DatafileProjectConfig.
|
22
|
+
|
23
|
+
def datafile; end
|
24
|
+
|
25
|
+
def account_id; end
|
26
|
+
|
27
|
+
def attributes; end
|
28
|
+
|
29
|
+
def audiences; end
|
30
|
+
|
31
|
+
def typed_audiences; end
|
32
|
+
|
33
|
+
def events; end
|
34
|
+
|
35
|
+
def experiments; end
|
36
|
+
|
37
|
+
def feature_flags; end
|
38
|
+
|
39
|
+
def groups; end
|
40
|
+
|
41
|
+
def project_id; end
|
42
|
+
|
43
|
+
def anonymize_ip; end
|
44
|
+
|
45
|
+
def bot_filtering; end
|
46
|
+
|
47
|
+
def revision; end
|
48
|
+
|
49
|
+
def sdk_key; end
|
50
|
+
|
51
|
+
def environment_key; end
|
52
|
+
|
53
|
+
def send_flag_decisions; end
|
54
|
+
|
55
|
+
def rollouts; end
|
56
|
+
|
57
|
+
def integrations; end
|
58
|
+
|
59
|
+
def public_key_for_odp; end
|
60
|
+
|
61
|
+
def host_for_odp; end
|
62
|
+
|
63
|
+
def all_segments; end
|
64
|
+
|
65
|
+
def experiment_running?(experiment); end
|
66
|
+
|
67
|
+
def get_experiment_from_key(experiment_key); end
|
68
|
+
|
69
|
+
def get_experiment_from_id(experiment_id); end
|
70
|
+
|
71
|
+
def get_experiment_key(experiment_id); end
|
72
|
+
|
73
|
+
def get_event_from_key(event_key); end
|
74
|
+
|
75
|
+
def get_audience_from_id(audience_id); end
|
76
|
+
|
77
|
+
def get_variation_from_id(experiment_key, variation_id); end
|
78
|
+
|
79
|
+
def get_variation_from_id_by_experiment_id(experiment_id, variation_id); end
|
80
|
+
|
81
|
+
def get_variation_id_from_key_by_experiment_id(experiment_id, variation_key); end
|
82
|
+
|
83
|
+
def get_variation_id_from_key(experiment_key, variation_key); end
|
84
|
+
|
85
|
+
def get_whitelisted_variations(experiment_id); end
|
86
|
+
|
87
|
+
def get_attribute_id(attribute_key); end
|
88
|
+
|
89
|
+
def variation_id_exists?(experiment_id, variation_id); end
|
90
|
+
|
91
|
+
def get_feature_flag_from_key(feature_flag_key); end
|
92
|
+
|
93
|
+
def get_feature_variable(feature_flag, variable_key); end
|
94
|
+
|
95
|
+
def get_rollout_from_id(rollout_id); end
|
96
|
+
|
97
|
+
def feature_experiment?(experiment_id); end
|
98
|
+
end
|
99
|
+
end
|
@@ -1,166 +1,166 @@
|
|
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
|
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
|