growthbook 1.2.0 → 1.2.2
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/lib/growthbook/conditions.rb +83 -8
- data/lib/growthbook/context.rb +2 -2
- data/lib/growthbook.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71807a4bbc1fb91e816a74e32d7d6c9e7d1dbed782b19efd3592fd5f5a944801
|
4
|
+
data.tar.gz: 03fa6cf71822d7f239afda323e9a28476721d64c6234b199103869207a2cd060
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af78de253f4b3c2ecfbcdde348237923b3ecdd0dbe547be7d0f177bc7dff2a6299d6f6ac7786c4e4e96c2c031ff46598897ef79214efeaba837cce4db2e3739b
|
7
|
+
data.tar.gz: fd4b68b94b0448dd1cd88b8aec1b96c1d76755133917c7a915a03b18e6a02cd2b2bc5d9f6735c51742d4af5a8707cec13f61ed571fd013059d45b207688a83f8
|
@@ -104,20 +104,68 @@ module Growthbook
|
|
104
104
|
false
|
105
105
|
end
|
106
106
|
|
107
|
+
def self.compare(val1, val2)
|
108
|
+
if val1.is_a?(Numeric) || val2.is_a?(Numeric)
|
109
|
+
val1 = val1.is_a?(Numeric) ? val1 : val1.to_f
|
110
|
+
val2 = val2.is_a?(Numeric) ? val2 : val2.to_f
|
111
|
+
end
|
112
|
+
|
113
|
+
return 1 if val1 > val2
|
114
|
+
return -1 if val1 < val2
|
115
|
+
|
116
|
+
0
|
117
|
+
end
|
118
|
+
|
107
119
|
def self.eval_operator_condition(operator, attribute_value, condition_value)
|
108
120
|
case operator
|
121
|
+
when '$veq'
|
122
|
+
padded_version_string(attribute_value) == padded_version_string(condition_value)
|
123
|
+
when '$vne'
|
124
|
+
padded_version_string(attribute_value) != padded_version_string(condition_value)
|
125
|
+
when '$vgt'
|
126
|
+
padded_version_string(attribute_value) > padded_version_string(condition_value)
|
127
|
+
when '$vgte'
|
128
|
+
padded_version_string(attribute_value) >= padded_version_string(condition_value)
|
129
|
+
when '$vlt'
|
130
|
+
padded_version_string(attribute_value) < padded_version_string(condition_value)
|
131
|
+
when '$vlte'
|
132
|
+
padded_version_string(attribute_value) <= padded_version_string(condition_value)
|
109
133
|
when '$eq'
|
110
|
-
|
134
|
+
begin
|
135
|
+
compare(attribute_value, condition_value).zero?
|
136
|
+
rescue StandardError
|
137
|
+
false
|
138
|
+
end
|
111
139
|
when '$ne'
|
112
|
-
|
140
|
+
begin
|
141
|
+
compare(attribute_value, condition_value) != 0
|
142
|
+
rescue StandardError
|
143
|
+
false
|
144
|
+
end
|
113
145
|
when '$lt'
|
114
|
-
|
146
|
+
begin
|
147
|
+
compare(attribute_value, condition_value).negative?
|
148
|
+
rescue StandardError
|
149
|
+
false
|
150
|
+
end
|
115
151
|
when '$lte'
|
116
|
-
|
152
|
+
begin
|
153
|
+
compare(attribute_value, condition_value) <= 0
|
154
|
+
rescue StandardError
|
155
|
+
false
|
156
|
+
end
|
117
157
|
when '$gt'
|
118
|
-
|
158
|
+
begin
|
159
|
+
compare(attribute_value, condition_value).positive?
|
160
|
+
rescue StandardError
|
161
|
+
false
|
162
|
+
end
|
119
163
|
when '$gte'
|
120
|
-
|
164
|
+
begin
|
165
|
+
compare(attribute_value, condition_value) >= 0
|
166
|
+
rescue StandardError
|
167
|
+
false
|
168
|
+
end
|
121
169
|
when '$regex'
|
122
170
|
silence_warnings do
|
123
171
|
re = Regexp.new(condition_value)
|
@@ -126,9 +174,13 @@ module Growthbook
|
|
126
174
|
false
|
127
175
|
end
|
128
176
|
when '$in'
|
129
|
-
condition_value.
|
177
|
+
return false unless condition_value.is_a?(Array)
|
178
|
+
|
179
|
+
in?(attribute_value, condition_value)
|
130
180
|
when '$nin'
|
131
|
-
|
181
|
+
return false unless condition_value.is_a?(Array)
|
182
|
+
|
183
|
+
!in?(attribute_value, condition_value)
|
132
184
|
when '$elemMatch'
|
133
185
|
elem_match(condition_value, attribute_value)
|
134
186
|
when '$size'
|
@@ -162,6 +214,29 @@ module Growthbook
|
|
162
214
|
end
|
163
215
|
end
|
164
216
|
|
217
|
+
def self.padded_version_string(input)
|
218
|
+
# Remove build info and leading `v` if any
|
219
|
+
# Split version into parts (both core version numbers and pre-release tags)
|
220
|
+
# "v1.2.3-rc.1+build123" -> ["1","2","3","rc","1"]
|
221
|
+
parts = input.gsub(/(^v|\+.*$)/, '').split(/[-.]/)
|
222
|
+
|
223
|
+
# If it's SemVer without a pre-release, add `~` to the end
|
224
|
+
# ["1","0","0"] -> ["1","0","0","~"]
|
225
|
+
# "~" is the largest ASCII character, so this will make "1.0.0" greater than "1.0.0-beta" for example
|
226
|
+
parts << '~' if parts.length == 3
|
227
|
+
|
228
|
+
# Left pad each numeric part with spaces so string comparisons will work ("9">"10", but " 9"<"10")
|
229
|
+
parts.map do |part|
|
230
|
+
/^[0-9]+$/.match?(part) ? part.rjust(5, ' ') : part
|
231
|
+
end.join('-')
|
232
|
+
end
|
233
|
+
|
234
|
+
def self.in?(actual, expected)
|
235
|
+
return expected.include?(actual) unless actual.is_a?(Array)
|
236
|
+
|
237
|
+
(actual & expected).any?
|
238
|
+
end
|
239
|
+
|
165
240
|
# Sets $VERBOSE for the duration of the block and back to its original
|
166
241
|
# value afterwards. Used for testing invalid regexes.
|
167
242
|
def self.silence_warnings
|
data/lib/growthbook/context.rb
CHANGED
@@ -329,7 +329,7 @@ module Growthbook
|
|
329
329
|
def included_in_rollout?(seed:, hash_attribute:, hash_version:, range:, coverage:)
|
330
330
|
return true if range.nil? && coverage.nil?
|
331
331
|
|
332
|
-
hash_value = get_attribute(hash_attribute)
|
332
|
+
hash_value = get_attribute(hash_attribute).to_s
|
333
333
|
|
334
334
|
return false if hash_value.empty?
|
335
335
|
|
@@ -344,7 +344,7 @@ module Growthbook
|
|
344
344
|
|
345
345
|
def filtered_out?(filters)
|
346
346
|
filters.any? do |filter|
|
347
|
-
hash_value = get_attribute(filter['attribute'] || 'id')
|
347
|
+
hash_value = get_attribute(filter['attribute'] || 'id').to_s
|
348
348
|
|
349
349
|
if hash_value.empty?
|
350
350
|
false
|
data/lib/growthbook.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: growthbook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GrowthBook
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|