determinator 2.1.0 → 2.2.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: 2e45f2f0be23112e3ef9836aa58973333a2bb409ac3718d02dcc464f117c4911
4
- data.tar.gz: 4489393bdd074715f545a1ce35419f0794fb47ed99a72af90f63d8885cf5c4fe
3
+ metadata.gz: 107d9dbd0e80451d7934e19754830957a212778442e66704246d824ceb666ff3
4
+ data.tar.gz: 8c3ef015c15768f2af180a70dac6fc08d1b91fac4386aca6becc93f038861875
5
5
  SHA512:
6
- metadata.gz: e9c6833636ff9724dd8c6533d532aee97edac0303168bda759d8e2a693221bd4f9d10c55bde8adcd51d8859d35902892188f023a15482aad054a273b426ff169
7
- data.tar.gz: ab4692c91ffcceb61018d08c165bf6c3bb7a6873103ffe91c6bf494d64f103a8f9a88e46462291024ea9476a00a9afdcfc32c863ade7807dc112857516e218e4
6
+ metadata.gz: 449e7fed34b10af10140322795618d1b43db7b6afe77d8e6b355d4e49f7f3f9fe637b7c6f59f78e79b6f0fc632363f191842f6d5cfa12d720ef77e675a1a9cb8
7
+ data.tar.gz: 2068ca12069b9255c9b91a097f74128af8cf0eb5b4f96e3cfd734eafd9301bb9db9989487444e2c20aaf3cc06468a2c90fb485eff7a49b57480e1c6c73634f71
@@ -1,3 +1,8 @@
1
+ # v2.1.0 (2019-07-25)
2
+
3
+ Feature:
4
+ - Adds support for `app_version` constraints (#60)
5
+
1
6
  # v2.1.0 (2019-05-01)
2
7
 
3
8
  Feature:
data/README.md CHANGED
@@ -194,6 +194,20 @@ determinator.which_variant(:my_experiment_name)
194
194
 
195
195
  Check the example Rails app in the `examples` directory for more information on how to make use of this gem.
196
196
 
197
+ ### app_version constraint
198
+
199
+ Feature flags and experiments can also be limited to actors with a [semantic versioning](https://semver.org/) property using an `app_version` property:
200
+ ```ruby
201
+ variant = determinator.which_variant(
202
+ :my_experiment_name,
203
+ properties: {
204
+ app_version: "1.2.3"
205
+ }
206
+ )
207
+ ```
208
+ The `app_version` constraint for that flag needs to follow ruby gem version constraints. We support the following operators: `>, <, >=, <=, ~>`. For example:
209
+ `app_version: ">=1.2.0"`
210
+
197
211
  ### Using Determinator in RSpec
198
212
 
199
213
  * Include the `spec_helper.rb`.
@@ -1,5 +1,6 @@
1
1
  require 'digest/md5'
2
2
  require 'determinator/actor_control'
3
+ require 'semantic'
3
4
 
4
5
  module Determinator
5
6
  class Control
@@ -115,12 +116,41 @@ module Determinator
115
116
 
116
117
  tg.constraints.reduce(true) do |fit, (scope, *required)|
117
118
  present = [*normalised_properties[scope]]
118
- fit && (required.flatten & present.flatten).any?
119
+ fit && matches_requirements?(scope, required, present)
119
120
  end
120
- # Must choose target group deterministically, if more than one match
121
+ # Must choose target group deterministically, if more than one match
121
122
  }.sort_by { |tg| tg.rollout }.last
122
123
  end
123
124
 
125
+ def matches_requirements?(scope, required, present)
126
+ case scope
127
+ when "app_version" then has_any_app_version?(required, present)
128
+ else has_any?(required, present)
129
+ end
130
+ end
131
+
132
+ def has_any?(required, present)
133
+ (required.flatten & present.flatten).any?
134
+ end
135
+
136
+ def has_any_app_version?(required, present)
137
+ invalid_properties = present.flatten.select do |v|
138
+ !v.match?(Semantic::Version::SemVerRegexp)
139
+ end
140
+ invalid_groups = required.flatten.select do |v|
141
+ !v.match?(/\d/)
142
+ end
143
+
144
+ return false if (invalid_properties + invalid_groups).any?
145
+
146
+ present.flatten.any? do |g|
147
+ given_version = Semantic::Version.new(g)
148
+ required.flatten.all? do |n|
149
+ given_version.satisfies?(n)
150
+ end
151
+ end
152
+ end
153
+
124
154
  def actor_identifier(feature, id, guid)
125
155
  case feature.bucket_type
126
156
  when :id
@@ -1,3 +1,3 @@
1
1
  module Determinator
2
- VERSION = '2.1.0'
2
+ VERSION = '2.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: determinator
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Hastings-Spital
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-01 00:00:00.000000000 Z
11
+ date: 2019-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -222,8 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
222
  - !ruby/object:Gem::Version
223
223
  version: '0'
224
224
  requirements: []
225
- rubyforge_project:
226
- rubygems_version: 2.7.6
225
+ rubygems_version: 3.0.4
227
226
  signing_key:
228
227
  specification_version: 4
229
228
  summary: Determine which experiments and features a specific actor should see.