prefab-cloud-ruby 0.15.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56f869e526c34a5e949e257b7d3bad480e9bfc35a32c228c00edf27bd1ffd0e1
4
- data.tar.gz: 34e5775b22b085295618be7f9c411923d3b643e16032ee70c7dc6340fed6009b
3
+ metadata.gz: 82381e4b656d675f4b98ee11601cde1920637e52eb5b039814247500207b9fa5
4
+ data.tar.gz: 4ff8914774523e745d512d506cc42f20e71a657fd8191d82e7e6ba1878bf04c9
5
5
  SHA512:
6
- metadata.gz: d5ce5a0a3c1dc3d0d8e258da5da8cd9f12975d8232c0775a39a205cbfb464074bf0fda9c7467d5bdbc4d04a4020d48aa68a816eaf1714ea5c3863a299178b2ac
7
- data.tar.gz: 5123db89a4947143ceff5e29f30cd655870193c6ec8afaa7eca9f2fb85d61c1da2eae18a1fd31fbd3ae5c580a4e438c93c330ecb54fffdaf05b94259b6dc96ec
6
+ metadata.gz: aac3fc04c779900ca92a6a859430a2fe7776bee90afba632456ff45e3bacb428dda61314d3cbf5a5b04ce61672e4591afb7ae0248b77352b381f52dcbbfb6f24
7
+ data.tar.gz: 5e2008ec802e2f32154bffb34804673187feb618a60edf2aba19666851787e14111e3d6e0fbeeebe8e3192cac56a32f3010b4d46ef507c3d16359886973ee90c
data/Gemfile CHANGED
@@ -8,6 +8,7 @@ gem 'google-protobuf', :platforms => :ruby
8
8
  gem 'googleapis-common-protos-types', :platforms => :ruby
9
9
 
10
10
  group :development do
11
+ gem 'benchmark-ips'
11
12
  gem 'grpc-tools', :platforms => :ruby
12
13
  gem "rdoc", "~> 3.12"
13
14
  gem "bundler"
data/Gemfile.lock CHANGED
@@ -3,6 +3,7 @@ GEM
3
3
  specs:
4
4
  addressable (2.8.0)
5
5
  public_suffix (>= 2.0.2, < 5.0)
6
+ benchmark-ips (2.10.0)
6
7
  builder (3.2.4)
7
8
  concurrent-ruby (1.1.10)
8
9
  daemons (1.4.1)
@@ -109,6 +110,7 @@ PLATFORMS
109
110
  ruby
110
111
 
111
112
  DEPENDENCIES
113
+ benchmark-ips
112
114
  bundler
113
115
  concurrent-ruby (~> 1.0, >= 1.0.5)
114
116
  faraday
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.15.0
1
+ 0.16.0
@@ -121,33 +121,40 @@ module Prefab
121
121
  int_value / MAX_32_FLOAT
122
122
  end
123
123
 
124
- # def criteria_match?(rule, lookup_key, attributes)
125
- #
126
- # end
127
124
  def criteria_match?(criteria, lookup_key, attributes)
128
- if criteria.operator == :ALWAYS_TRUE
129
- return true
130
- elsif criteria.operator == :LOOKUP_KEY_IN
131
- return criteria.values.include?(lookup_key)
132
- elsif criteria.operator == :LOOKUP_KEY_NOT_IN
133
- return !criteria.values.include?(lookup_key)
134
- elsif criteria.operator == :IN_SEG
135
- return segment_matches(criteria.values, lookup_key, attributes).any?
136
- elsif criteria.operator == :NOT_IN_SEG
137
- return segment_matches(criteria.values, lookup_key, attributes).none?
138
- elsif criteria.operator == :PROP_IS_ONE_OF
139
- return criteria.values.include?(attributes[criteria.property]) || criteria.values.include?(attributes[criteria.property.to_sym])
140
- elsif criteria.operator == :PROP_IS_NOT_ONE_OF
141
- return !(criteria.values.include?(attributes[criteria.property]) || criteria.values.include?(attributes[criteria.property.to_sym]))
125
+ case criteria.operator
126
+ when :ALWAYS_TRUE
127
+ true
128
+ when :LOOKUP_KEY_IN
129
+ criteria.values.include?(lookup_key)
130
+ when :LOOKUP_KEY_NOT_IN
131
+ !criteria.values.include?(lookup_key)
132
+ when :IN_SEG
133
+ segment_matches?(criteria.values, lookup_key, attributes)
134
+ when :NOT_IN_SEG
135
+ !segment_matches?(criteria.values, lookup_key, attributes)
136
+ when :PROP_IS_ONE_OF
137
+ criteria.values.include?(attribute_value(attributes, criteria.property))
138
+ when :PROP_IS_NOT_ONE_OF
139
+ !criteria.values.include?(attribute_value(attributes, criteria.property))
140
+ when :PROP_ENDS_WITH_ONE_OF
141
+ criteria.values.any? { |value| attribute_value(attributes, criteria.property)&.end_with?(value) }
142
+ when :PROP_DOES_NOT_END_WITH_ONE_OF
143
+ criteria.values.none? { |value| attribute_value(attributes, criteria.property)&.end_with?(value) }
144
+ else
145
+ @base_client.log.info("Unknown Operator: #{criteria.operator}")
146
+ false
142
147
  end
143
- @base_client.log.info("Unknown Operator")
144
- false
145
148
  end
146
149
 
147
- # evaluate each segment key and return whether each one matches
150
+ def attribute_value(attributes, property)
151
+ attributes[property] || attributes[property.to_sym]
152
+ end
153
+
154
+ # evaluate each segment key and return whether any match
148
155
  # there should be an associated segment available as a standard config obj
149
- def segment_matches(segment_keys, lookup_key, attributes)
150
- segment_keys.map do |segment_key|
156
+ def segment_matches?(segment_keys, lookup_key, attributes)
157
+ segment_keys.any? do |segment_key|
151
158
  segment = @base_client.config_client.get(segment_key)
152
159
  if segment.nil?
153
160
  @base_client.log.info("Missing Segment")
@@ -160,9 +167,9 @@ module Prefab
160
167
 
161
168
  # does a given segment match?
162
169
  def segment_match?(segment, lookup_key, attributes)
163
- segment.criterion.map do |criteria|
170
+ segment.criterion.any? do |criteria|
164
171
  criteria_match?(criteria, lookup_key, attributes)
165
- end.any?
172
+ end
166
173
  end
167
174
  end
168
175
  end
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: prefab-cloud-ruby 0.15.0 ruby lib
5
+ # stub: prefab-cloud-ruby 0.16.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "prefab-cloud-ruby".freeze
9
- s.version = "0.15.0"
9
+ s.version = "0.16.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Jeff Dwyer".freeze]
14
- s.date = "2022-08-28"
14
+ s.date = "2022-09-01"
15
15
  s.description = "RateLimits & Config as a service".freeze
16
16
  s.email = "jdwyer@prefab.cloud".freeze
17
17
  s.extra_rdoc_files = [
@@ -81,6 +81,7 @@ Gem::Specification.new do |s|
81
81
  s.add_runtime_dependency(%q<grpc>.freeze, [">= 0"])
82
82
  s.add_runtime_dependency(%q<google-protobuf>.freeze, [">= 0"])
83
83
  s.add_runtime_dependency(%q<googleapis-common-protos-types>.freeze, [">= 0"])
84
+ s.add_development_dependency(%q<benchmark-ips>.freeze, [">= 0"])
84
85
  s.add_development_dependency(%q<grpc-tools>.freeze, [">= 0"])
85
86
  s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
86
87
  s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
@@ -94,6 +95,7 @@ Gem::Specification.new do |s|
94
95
  s.add_dependency(%q<grpc>.freeze, [">= 0"])
95
96
  s.add_dependency(%q<google-protobuf>.freeze, [">= 0"])
96
97
  s.add_dependency(%q<googleapis-common-protos-types>.freeze, [">= 0"])
98
+ s.add_dependency(%q<benchmark-ips>.freeze, [">= 0"])
97
99
  s.add_dependency(%q<grpc-tools>.freeze, [">= 0"])
98
100
  s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
99
101
  s.add_dependency(%q<bundler>.freeze, [">= 0"])
@@ -299,6 +299,66 @@ class TestFeatureFlagClient < Minitest::Test
299
299
 
300
300
  end
301
301
 
302
+ def test_prop_ends_with_one_of
303
+ feature = "FlagName"
304
+
305
+ variants = [
306
+ Prefab::FeatureFlagVariant.new(bool: false),
307
+ Prefab::FeatureFlagVariant.new(bool: true)
308
+ ]
309
+ flag = Prefab::FeatureFlag.new(
310
+ active: true,
311
+ inactive_variant_idx: 1,
312
+ rules: [
313
+ Prefab::Rule.new(
314
+ criteria: Prefab::Criteria.new(operator: Prefab::Criteria::CriteriaOperator::PROP_ENDS_WITH_ONE_OF,
315
+ property: "email",
316
+ values: ["@example.com"]),
317
+ variant_weights: [
318
+ Prefab::VariantWeight.new(weight: 100, variant_idx: 2)
319
+ ]
320
+ )
321
+ ]
322
+ )
323
+
324
+ assert_equal false, evaluate(feature, "user:0", {}, flag, variants)
325
+ assert_equal true, evaluate(feature, "user:0", {email: "test@example.com"}, flag, variants)
326
+ assert_equal true, evaluate(feature, "user:0", {"email" => "test@example.com"}, flag, variants)
327
+ end
328
+
329
+ def test_prop_does_not_end_with_one_of
330
+ feature = "FlagName"
331
+
332
+ variants = [
333
+ Prefab::FeatureFlagVariant.new(bool: false),
334
+ Prefab::FeatureFlagVariant.new(bool: true)
335
+ ]
336
+ flag = Prefab::FeatureFlag.new(
337
+ active: true,
338
+ inactive_variant_idx: 1,
339
+ rules: [
340
+ Prefab::Rule.new(
341
+ criteria: Prefab::Criteria.new(operator: Prefab::Criteria::CriteriaOperator::PROP_DOES_NOT_END_WITH_ONE_OF,
342
+ property: "email",
343
+ values: ["@example.com"]),
344
+ variant_weights: [
345
+ Prefab::VariantWeight.new(weight: 100, variant_idx: 2)
346
+ ]
347
+ ),
348
+ Prefab::Rule.new(
349
+ criteria: Prefab::Criteria.new(operator: Prefab::Criteria::CriteriaOperator::ALWAYS_TRUE),
350
+ variant_weights: [
351
+ Prefab::VariantWeight.new(weight: 100, variant_idx: 1)
352
+ ]
353
+ )
354
+ ],
355
+ )
356
+
357
+ assert_equal true, evaluate(feature, "user:0", {}, flag, variants)
358
+ assert_equal false, evaluate(feature, "user:0", {email: "test@example.com"}, flag, variants)
359
+ assert_equal false, evaluate(feature, "user:0", {"email" => "test@example.com"}, flag, variants)
360
+ end
361
+
302
362
  def evaluate(feature_name, lookup_key, attributes, flag, variants)
303
363
  variant = @client.get_variant(feature_name, lookup_key, attributes, flag, variants)
304
364
  @client.value_of_variant(variant)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prefab-cloud-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Dwyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-28 00:00:00.000000000 Z
11
+ date: 2022-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -100,6 +100,20 @@ dependencies:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: benchmark-ips
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
103
117
  - !ruby/object:Gem::Dependency
104
118
  name: grpc-tools
105
119
  requirement: !ruby/object:Gem::Requirement