unleash 4.4.2 → 4.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/pull_request.yml +4 -2
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +108 -0
- data/README.md +48 -22
- data/bin/console +1 -0
- data/lib/unleash/client.rb +2 -5
- data/lib/unleash/context.rb +5 -0
- data/lib/unleash/feature_toggle.rb +9 -4
- data/lib/unleash/metrics.rb +3 -3
- data/lib/unleash/strategy/flexible_rollout.rb +11 -2
- data/lib/unleash/version.rb +1 -1
- data/unleash-client.gemspec +9 -4
- metadata +15 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f59bcc61a5b2adc71f82f31ee80d02e8957854b86b85147fa33ad1f8bd3ee3ab
|
4
|
+
data.tar.gz: 691a79a57aba051ab5111d71a038e6c8f2d21ee747ee39fdb6676108fc1ef777
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6d4c9efc598b2eae5958c7c68c362832988d6ed8cc4f51d47e0ede588b37599c0d104d4a7c08060761564653bdb68d1c6a20dedafc7b6d3bbb22c489ac8c4ec
|
7
|
+
data.tar.gz: 003b0d345c5f1ccc22361ddce4213e40054ec57a7e3404ca8d99ce3b120fb072b506a75f1fe64053e7b57c67688ed0b6aa6532dd99f3f7bfaa729c520d2c290c
|
@@ -10,11 +10,11 @@ jobs:
|
|
10
10
|
timeout-minutes: 30
|
11
11
|
runs-on: ubuntu-latest
|
12
12
|
steps:
|
13
|
-
- uses: actions/checkout@
|
13
|
+
- uses: actions/checkout@v3
|
14
14
|
- name: Set up Ruby
|
15
15
|
uses: ruby/setup-ruby@v1
|
16
16
|
with:
|
17
|
-
ruby-version: "
|
17
|
+
ruby-version: "3.0"
|
18
18
|
bundler-cache: true
|
19
19
|
- name: Run RuboCop
|
20
20
|
run: bundle exec rubocop
|
@@ -38,6 +38,8 @@ jobs:
|
|
38
38
|
- 2.6
|
39
39
|
- 2.5
|
40
40
|
|
41
|
+
needs:
|
42
|
+
- lint
|
41
43
|
steps:
|
42
44
|
- uses: actions/checkout@v3
|
43
45
|
- name: Set up Ruby ${{ matrix.ruby-version }}
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
|
2
|
+
# Changelog
|
3
|
+
|
4
|
+
All notable changes to this project will be documented in this file.
|
5
|
+
|
6
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
7
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
8
|
+
|
9
|
+
Note: These changes are not considered notable:
|
10
|
+
- build
|
11
|
+
- documentation
|
12
|
+
- dependencies
|
13
|
+
|
14
|
+
## [Unreleased]
|
15
|
+
|
16
|
+
## [4.4.4] - 2023-07-05
|
17
|
+
### Fixed
|
18
|
+
- flexible rollout strategy without context (#146)
|
19
|
+
- The flexible rollout strategy should evaluate default and random stickiness even if context is not provided.
|
20
|
+
|
21
|
+
## [4.4.3] - 2023-06-14
|
22
|
+
### Added
|
23
|
+
- Add Context#to_h method (#136)
|
24
|
+
|
25
|
+
### Fixed
|
26
|
+
- Bootstrapped variants now work when client is disabled (#138)
|
27
|
+
- Variant metrics are now sent correctly to Unleash. Fixed a typo in the payload name. (#145)
|
28
|
+
|
29
|
+
### Changed
|
30
|
+
- Automatically disable metrics/MetricsReporter when client is disabled (#139) (#140)
|
31
|
+
|
32
|
+
## [4.4.2] - 2023-01-05
|
33
|
+
### Added
|
34
|
+
- Add Client#disabled? method (#130)
|
35
|
+
|
36
|
+
## [4.4.1] - 2022-12-07
|
37
|
+
### Fixed
|
38
|
+
- exception no longer bubbles up in constraints when context is nil (#127)
|
39
|
+
- variants metrics did count toggles correctly (#126)
|
40
|
+
- prevent race condition when manipulating metrics data (#122)
|
41
|
+
- allow passing user_id as integer (#119)
|
42
|
+
|
43
|
+
## [4.4.0] - 2022-09-19
|
44
|
+
### Added
|
45
|
+
- Allow custom strategies (#96)
|
46
|
+
- Global segments (#114)
|
47
|
+
|
48
|
+
### Fixed
|
49
|
+
- Initializing client configuration from constructor (#117)
|
50
|
+
- Support int context in set comparison (#115)
|
51
|
+
|
52
|
+
## [4.3.0] - 2023-07-14
|
53
|
+
### Added
|
54
|
+
- dynamic http headers via Proc or Lambda (#107)
|
55
|
+
|
56
|
+
### Fixed
|
57
|
+
- Fixed ToggleFetcher#save! to close opened files on failure. (#97)
|
58
|
+
|
59
|
+
### Changed
|
60
|
+
- Refactored ToggleFetcher#read! (#106)
|
61
|
+
|
62
|
+
## [4.2.1] - 2022-03-29
|
63
|
+
### Fixed
|
64
|
+
- correct logic for default values on feature toggles so toggle value respected when toggle exists and default is true (#93)
|
65
|
+
|
66
|
+
## [4.2.0] - 2022-03-18
|
67
|
+
### Added
|
68
|
+
- Advanced constraints operators (#92)
|
69
|
+
|
70
|
+
### Changed
|
71
|
+
- Default to the client never giving up trying to reach the server even after repeated failures (#91)
|
72
|
+
|
73
|
+
## [4.1.0] - 2022-02-11
|
74
|
+
### Added
|
75
|
+
- feat: Implement custom bootstrapping on startup (#88)
|
76
|
+
- feat: add support for cidr in `RemoteAddress` strategy (#77)
|
77
|
+
|
78
|
+
### Changed
|
79
|
+
- default values for `metrics_interval` to `60s` and `retry_limit` to `5` (#78)
|
80
|
+
|
81
|
+
## [4.0.0] - 2021-12-16
|
82
|
+
### Added
|
83
|
+
- Support for projects query (requires unleash 4.x) (#38)
|
84
|
+
- Allow passing blocks to is_enabled? to determine default_result (#33)
|
85
|
+
- Implement custom stickiness (#69)
|
86
|
+
- Allow using custom_http_headers from the CLI utility (#75)
|
87
|
+
|
88
|
+
### Fixed
|
89
|
+
- Allow context to correctly resolve camelCase property values (#74)
|
90
|
+
- Avoid unlikely situation of config changing under the read operation due to backup path file being incorrectly set (#63)
|
91
|
+
|
92
|
+
### Changed
|
93
|
+
- change how we handle the server api url (avoid double slashes in urls used for API calls.)
|
94
|
+
- default values: refresh_interval => 10, metrics_interval=> 30 (#59)
|
95
|
+
- changed metrics reporting behavior (#66)
|
96
|
+
- only send metrics if there is data to send. (#58)
|
97
|
+
- in Client#get_variant() allow context and fallback_variant as nil (#51)
|
98
|
+
|
99
|
+
[unreleased]: https://git1hub.com/unleash/unleash-client-ruby/compare/v4.4.3...HEAD
|
100
|
+
[4.4.3]: https://github.com/unleash/unleash-client-ruby/compare/v4.4.2...v4.4.3
|
101
|
+
[4.4.2]: https://github.com/unleash/unleash-client-ruby/compare/v4.4.1...v4.4.2
|
102
|
+
[4.4.1]: https://github.com/unleash/unleash-client-ruby/compare/v4.4.0...v4.4.1
|
103
|
+
[4.4.0]: https://github.com/unleash/unleash-client-ruby/compare/v4.3.0...v4.4.0
|
104
|
+
[4.3.0]: https://github.com/unleash/unleash-client-ruby/compare/v4.2.1...v4.3.0
|
105
|
+
[4.2.1]: https://github.com/unleash/unleash-client-ruby/compare/v4.2.0...v4.2.1
|
106
|
+
[4.2.0]: https://github.com/unleash/unleash-client-ruby/compare/v4.1.0...v4.2.0
|
107
|
+
[4.1.0]: https://github.com/unleash/unleash-client-ruby/compare/v4.0.0...v4.1.0
|
108
|
+
[4.0.0]: https://github.com/unleash/unleash-client-ruby/compare/v3.2.5...v4.0.0
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ Leverage the [Unleash Server](https://github.com/Unleash/unleash) for powerful f
|
|
25
25
|
Add this line to your application's Gemfile:
|
26
26
|
|
27
27
|
```ruby
|
28
|
-
gem 'unleash', '~> 4.4.
|
28
|
+
gem 'unleash', '~> 4.4.4'
|
29
29
|
```
|
30
30
|
|
31
31
|
And then execute:
|
@@ -86,12 +86,12 @@ Argument | Description | Required? | Type | Default Value|
|
|
86
86
|
`url` | Unleash server URL. | Y | String | N/A |
|
87
87
|
`app_name` | Name of your program. | Y | String | N/A |
|
88
88
|
`instance_id` | Identifier for the running instance of program. Important so you can trace back to where metrics are being collected from. **Highly recommended be be set.** | N | String | random UUID |
|
89
|
-
`environment` |
|
89
|
+
`environment` | Unleash context option. Could be for example `prod` or `dev`. Not yet in use. **Not** the same as the SDK's [Unleash environment](https://docs.getunleash.io/reference/environments). | N | String | `default` |
|
90
90
|
`project_name` | Name of the project to retrieve features from. If not set, all feature flags will be retrieved. | N | String | nil |
|
91
91
|
`refresh_interval` | How often the unleash client should check with the server for configuration changes. | N | Integer | 15 |
|
92
92
|
`metrics_interval` | How often the unleash client should send metrics to server. | N | Integer | 60 |
|
93
|
-
`disable_client` | Disables all communication with the Unleash server, effectively taking it *offline*. If set, `is_enabled?` will always answer with the `default_value` and configuration validation is skipped. Defeats the entire purpose of using unleash,
|
94
|
-
`disable_metrics` | Disables sending metrics to Unleash server. | N | Boolean | `false` |
|
93
|
+
`disable_client` | Disables all communication with the Unleash server, effectively taking it *offline*. If set, `is_enabled?` will always answer with the `default_value` and configuration validation is skipped. Will also forcefully set `disable_metrics` to `true`. Defeats the entire purpose of using unleash, except when running tests. | N | Boolean | `false` |
|
94
|
+
`disable_metrics` | Disables sending metrics to Unleash server. If the `disable_client` option is set to `true`, then this option will also be set to `true`, regardless of the value provided. | N | Boolean | `false` |
|
95
95
|
`custom_http_headers` | Custom headers to send to Unleash. As of Unleash v4.0.0, the `Authorization` header is required. For example: `{'Authorization': '<API token>'}` | N | Hash/Proc | {} |
|
96
96
|
`timeout` | How long to wait for the connection to be established or wait in reading state (open_timeout/read_timeout) | N | Integer | 30 |
|
97
97
|
`retry_limit` | How many consecutive failures in connecting to the Unleash server are allowed before giving up. The default is to retry indefinitely. | N | Float::INFINITY | 5 |
|
@@ -145,7 +145,6 @@ Unleash.configure do |config|
|
|
145
145
|
config.url = 'https://unleash.herokuapp.com/api'
|
146
146
|
# config.instance_id = "#{Socket.gethostname}"
|
147
147
|
config.logger = Rails.logger
|
148
|
-
config.environment = Rails.env
|
149
148
|
end
|
150
149
|
|
151
150
|
UNLEASH = Unleash::Client.new
|
@@ -180,7 +179,6 @@ Then you may keep the client configuration still in `config/initializers/unleash
|
|
180
179
|
```ruby
|
181
180
|
Unleash.configure do |config|
|
182
181
|
config.app_name = Rails.application.class.parent.to_s
|
183
|
-
config.environment = Rails.env
|
184
182
|
config.url = 'https://unleash.herokuapp.com/api'
|
185
183
|
config.custom_http_headers = {'Authorization': '<API token>'}
|
186
184
|
end
|
@@ -228,7 +226,6 @@ on_worker_boot do
|
|
228
226
|
|
229
227
|
::UNLEASH = Unleash::Client.new(
|
230
228
|
app_name: 'my_rails_app',
|
231
|
-
environment: 'development',
|
232
229
|
url: 'https://unleash.herokuapp.com/api',
|
233
230
|
custom_http_headers: {'Authorization': '<API token>'},
|
234
231
|
)
|
@@ -254,7 +251,6 @@ PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
|
254
251
|
config.app_name = Rails.application.class.parent.to_s
|
255
252
|
# config.instance_id = "#{Socket.gethostname}"
|
256
253
|
config.logger = Rails.logger
|
257
|
-
config.environment = Rails.env
|
258
254
|
config.url = 'https://unleash.herokuapp.com/api'
|
259
255
|
config.custom_http_headers = {'Authorization': '<API token>'}
|
260
256
|
end
|
@@ -310,9 +306,6 @@ Then wherever in your application that you need a feature toggle, you can use:
|
|
310
306
|
if UNLEASH.is_enabled? "AwesomeFeature", @unleash_context
|
311
307
|
puts "AwesomeFeature is enabled"
|
312
308
|
end
|
313
|
-
if UNLEASH.is_disabled? "AwesomeFeature", @unleash_context
|
314
|
-
puts "AwesomeFeature is disabled"
|
315
|
-
end
|
316
309
|
```
|
317
310
|
|
318
311
|
or if client is set in `Rails.configuration.unleash`:
|
@@ -321,18 +314,33 @@ or if client is set in `Rails.configuration.unleash`:
|
|
321
314
|
if Rails.configuration.unleash.is_enabled? "AwesomeFeature", @unleash_context
|
322
315
|
puts "AwesomeFeature is enabled"
|
323
316
|
end
|
324
|
-
|
325
|
-
|
317
|
+
```
|
318
|
+
|
319
|
+
If you don't want to check a feature is disabled with `unless`, you can also use `is_disabled?`:
|
320
|
+
|
321
|
+
```ruby
|
322
|
+
# so instead of:
|
323
|
+
unless UNLEASH.is_enabled? "AwesomeFeature", @unleash_context
|
324
|
+
puts "AwesomeFeature is disabled"
|
325
|
+
end
|
326
|
+
|
327
|
+
# it might be more intelligible:
|
328
|
+
if UNLEASH.is_disabled? "AwesomeFeature", @unleash_context
|
329
|
+
puts "AwesomeFeature is disabled"
|
326
330
|
end
|
327
331
|
```
|
328
332
|
|
329
333
|
If the feature is not found in the server, it will by default return false.
|
330
|
-
However you can override that by setting the default return value to `true`:
|
334
|
+
However, you can override that by setting the default return value to `true`:
|
331
335
|
|
332
336
|
```ruby
|
333
337
|
if UNLEASH.is_enabled? "AwesomeFeature", @unleash_context, true
|
334
338
|
puts "AwesomeFeature is enabled by default"
|
335
339
|
end
|
340
|
+
# or
|
341
|
+
if UNLEASH.is_disabled? "AwesomeFeature", @unleash_context, true
|
342
|
+
puts "AwesomeFeature is disabled by default"
|
343
|
+
end
|
336
344
|
```
|
337
345
|
|
338
346
|
Another possibility is to send a block, [Lambda](https://ruby-doc.org/core-3.0.1/Kernel.html#method-i-lambda) or [Proc](https://ruby-doc.org/core-3.0.1/Proc.html#method-i-yield)
|
@@ -355,7 +363,7 @@ awesomeness = 10
|
|
355
363
|
@unleash_context.properties[:coolness] = 10
|
356
364
|
|
357
365
|
if UNLEASH.is_enabled?("AwesomeFeature", @unleash_context) { |feat, ctx| awesomeness >= 6 && ctx.properties[:coolness] >= 8 }
|
358
|
-
puts "AwesomeFeature is enabled by default if both the user has a high
|
366
|
+
puts "AwesomeFeature is enabled by default if both the user has a high enough coolness and the application has a high enough awesomeness"
|
359
367
|
end
|
360
368
|
```
|
361
369
|
|
@@ -364,12 +372,12 @@ Note:
|
|
364
372
|
- The client will evaluate the fallback function once per call of `is_enabled()`.
|
365
373
|
Please keep this in mind when creating your fallback function!
|
366
374
|
- The returned value of the block should be a boolean.
|
367
|
-
However the client will coerce the result to boolean via `!!`.
|
375
|
+
However, the client will coerce the result to boolean via `!!`.
|
368
376
|
- If both a `default_value` and `fallback_function` are supplied,
|
369
377
|
the client will define the default value by `OR`ing the default value and the output of the fallback function.
|
370
378
|
|
371
379
|
|
372
|
-
Alternatively by using `if_enabled` you can send a code block to be executed as a parameter:
|
380
|
+
Alternatively by using `if_enabled` (or `if_disabled`) you can send a code block to be executed as a parameter:
|
373
381
|
|
374
382
|
```ruby
|
375
383
|
UNLEASH.if_enabled "AwesomeFeature", @unleash_context, true do
|
@@ -377,7 +385,7 @@ UNLEASH.if_enabled "AwesomeFeature", @unleash_context, true do
|
|
377
385
|
end
|
378
386
|
```
|
379
387
|
|
380
|
-
Note: `if_enabled` only
|
388
|
+
Note: `if_enabled` (and `if_disabled`) only support `default_value`, but not `fallback_function`.
|
381
389
|
|
382
390
|
##### Variations
|
383
391
|
|
@@ -498,7 +506,7 @@ In order for strategy to work correctly it should support two methods `name` and
|
|
498
506
|
```ruby
|
499
507
|
class MyCustomStrategy
|
500
508
|
def name
|
501
|
-
'
|
509
|
+
'myCustomStrategy'
|
502
510
|
end
|
503
511
|
|
504
512
|
def is_enabled?(params = {}, context = nil)
|
@@ -513,19 +521,37 @@ end
|
|
513
521
|
|
514
522
|
## Development
|
515
523
|
|
516
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
524
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
525
|
+
Then, run `rake spec` to run the tests.
|
526
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
517
527
|
|
518
|
-
This SDK is also built against the Unleash Client Specification tests.
|
528
|
+
This SDK is also built against the Unleash Client Specification tests.
|
529
|
+
To run the Ruby SDK against this test suite, you'll need to have a copy on your machine, you can clone the repository directly using:
|
519
530
|
|
520
531
|
`git clone --depth 5 --branch v4.2.2 https://github.com/Unleash/client-specification.git client-specification`
|
521
532
|
|
522
533
|
After doing this, `rake spec` will also run the client specification tests.
|
523
534
|
|
524
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
535
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
536
|
+
|
537
|
+
## Releasing
|
538
|
+
|
539
|
+
Choose a new version number following [Semantic Versioning](https://semver.org/spec/v2.0.0.html) semantics and then:
|
540
|
+
|
541
|
+
- update the version number in [./lib/unleash/version.rb](./lib/unleash/version.rb),
|
542
|
+
- if a major or minor version bump, update the [Installation section](#Installation) in [README.md](README.md)
|
543
|
+
- update [CHANGELOG.md](CHANGELOG.md) following the format on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
|
544
|
+
- commit with message `chore: bump version to x.y.z`
|
545
|
+
- then run `bundle exec rake release`
|
546
|
+
- This will create a git tag for the version on the current commit,
|
547
|
+
- push git commits and tags to origin and
|
548
|
+
- push the `.gem` file to [rubygems.org](https://rubygems.org)
|
525
549
|
|
526
550
|
|
527
551
|
## Contributing
|
528
552
|
|
529
553
|
Bug reports and pull requests are welcome on GitHub at https://github.com/unleash/unleash-client-ruby.
|
530
554
|
|
555
|
+
Be sure to run both `bundle exec rspec` and `bundle exec rubocop` in your branch before creating a pull request.
|
556
|
+
|
531
557
|
Please include tests with any pull requests, to avoid regressions.
|
data/bin/console
CHANGED
data/lib/unleash/client.rb
CHANGED
@@ -21,6 +21,8 @@ module Unleash
|
|
21
21
|
Unleash.toggle_fetcher = Unleash::ToggleFetcher.new
|
22
22
|
if Unleash.configuration.disable_client
|
23
23
|
Unleash.logger.warn "Unleash::Client is disabled! Will only return default (or bootstrapped if available) results!"
|
24
|
+
Unleash.logger.warn "Unleash::Client is disabled! Metrics and MetricsReporter are also disabled!"
|
25
|
+
Unleash.configuration.disable_metrics = true
|
24
26
|
return
|
25
27
|
end
|
26
28
|
|
@@ -72,11 +74,6 @@ module Unleash
|
|
72
74
|
def get_variant(feature, context = Unleash::Context.new, fallback_variant = disabled_variant)
|
73
75
|
Unleash.logger.debug "Unleash::Client.get_variant for feature: #{feature} with context #{context}"
|
74
76
|
|
75
|
-
if Unleash.configuration.disable_client
|
76
|
-
Unleash.logger.debug "unleash_client is disabled! Always returning #{fallback_variant} for feature #{feature}!"
|
77
|
-
return fallback_variant
|
78
|
-
end
|
79
|
-
|
80
77
|
toggle_as_hash = Unleash&.toggles&.select{ |toggle| toggle['name'] == feature }&.first
|
81
78
|
|
82
79
|
if toggle_as_hash.nil?
|
data/lib/unleash/context.rb
CHANGED
@@ -23,6 +23,11 @@ module Unleash
|
|
23
23
|
",app_name=#{@app_name},environment=#{@environment}>"
|
24
24
|
end
|
25
25
|
|
26
|
+
def to_h
|
27
|
+
ATTRS.map{ |attr| [attr, self.send(attr)] }.to_h.merge(properties: @properties)
|
28
|
+
end
|
29
|
+
|
30
|
+
# returns the value found for the key in the context, or raises a KeyError exception if not found.
|
26
31
|
def get_by_name(name)
|
27
32
|
normalized_name = underscore(name).to_sym
|
28
33
|
|
@@ -97,10 +97,15 @@ module Unleash
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def variant_salt(context, stickiness = "default")
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
100
|
+
begin
|
101
|
+
return context.get_by_name(stickiness) if !context.nil? && stickiness != "default"
|
102
|
+
rescue KeyError
|
103
|
+
Unleash.logger.warn "Custom stickiness key (#{stickiness}) not found in the provided context #{context}. " \
|
104
|
+
"Falling back to default behavior."
|
105
|
+
end
|
106
|
+
return context.user_id unless context&.user_id.to_s.empty?
|
107
|
+
return context.session_id unless context&.session_id.to_s.empty?
|
108
|
+
return context.remote_address unless context&.remote_address.to_s.empty?
|
104
109
|
|
105
110
|
SecureRandom.random_number
|
106
111
|
end
|
data/lib/unleash/metrics.rb
CHANGED
@@ -26,9 +26,9 @@ module Unleash
|
|
26
26
|
self.features_lock.synchronize do
|
27
27
|
self.features[feature] = { yes: 0, no: 0 } unless self.features.include? feature
|
28
28
|
self.features[feature][choice] += 1
|
29
|
-
self.features[feature]['
|
30
|
-
self.features[feature]['
|
31
|
-
self.features[feature]['
|
29
|
+
self.features[feature]['variants'] = {} unless self.features[feature].include? 'variants'
|
30
|
+
self.features[feature]['variants'][variant] = 0 unless self.features[feature]['variants'].include? variant
|
31
|
+
self.features[feature]['variants'][variant] += 1
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -10,9 +10,10 @@ module Unleash
|
|
10
10
|
# need: params['percentage']
|
11
11
|
def is_enabled?(params = {}, context = nil)
|
12
12
|
return false unless params.is_a?(Hash)
|
13
|
-
return false unless context.instance_of?(Unleash::Context)
|
14
13
|
|
15
14
|
stickiness = params.fetch('stickiness', 'default')
|
15
|
+
return false if context_invalid?(stickiness, context)
|
16
|
+
|
16
17
|
stickiness_id = resolve_stickiness(stickiness, context)
|
17
18
|
|
18
19
|
begin
|
@@ -32,6 +33,12 @@ module Unleash
|
|
32
33
|
|
33
34
|
private
|
34
35
|
|
36
|
+
def context_invalid?(stickiness, context)
|
37
|
+
return false if ['random', 'default'].include?(stickiness)
|
38
|
+
|
39
|
+
!context.instance_of?(Unleash::Context)
|
40
|
+
end
|
41
|
+
|
35
42
|
def random
|
36
43
|
Random.rand(0..100)
|
37
44
|
end
|
@@ -41,7 +48,9 @@ module Unleash
|
|
41
48
|
when 'random'
|
42
49
|
random
|
43
50
|
when 'default'
|
44
|
-
|
51
|
+
return random unless context.instance_of?(Unleash::Context)
|
52
|
+
|
53
|
+
context&.user_id || context&.session_id || random
|
45
54
|
else
|
46
55
|
begin
|
47
56
|
context.get_by_name(stickiness)
|
data/lib/unleash/version.rb
CHANGED
data/unleash-client.gemspec
CHANGED
@@ -23,15 +23,20 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.require_paths = ["lib"]
|
24
24
|
spec.required_ruby_version = ">= 2.5"
|
25
25
|
|
26
|
-
spec.add_dependency "murmurhash3", "~> 0.1.
|
26
|
+
spec.add_dependency "murmurhash3", "~> 0.1.7"
|
27
27
|
|
28
28
|
spec.add_development_dependency "bundler", "~> 2.1"
|
29
29
|
spec.add_development_dependency "rake", "~> 12.3"
|
30
|
-
spec.add_development_dependency "rspec", "~> 3.
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.12"
|
31
31
|
spec.add_development_dependency "rspec-json_expectations", "~> 2.2"
|
32
|
-
spec.add_development_dependency "webmock", "~> 3.
|
32
|
+
spec.add_development_dependency "webmock", "~> 3.18.1"
|
33
|
+
|
34
|
+
# rubocop:disable Gemspec/RubyVersionGlobalsUsage, Style/IfUnlessModifier
|
35
|
+
if Gem::Version.new(RUBY_VERSION) > Gem::Version.new('3.0')
|
36
|
+
spec.add_development_dependency "rubocop", "~> 1.51.0"
|
37
|
+
end
|
38
|
+
# rubocop:enable Gemspec/RubyVersionGlobalsUsage, Style/IfUnlessModifier
|
33
39
|
|
34
|
-
spec.add_development_dependency "rubocop", "~> 1.28.2"
|
35
40
|
spec.add_development_dependency "simplecov", "~> 0.21.2"
|
36
41
|
spec.add_development_dependency "simplecov-lcov", "~> 0.8.0"
|
37
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unleash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.4.
|
4
|
+
version: 4.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Renato Arruda
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: murmurhash3
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.1.
|
19
|
+
version: 0.1.7
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.1.
|
26
|
+
version: 0.1.7
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '3.
|
61
|
+
version: '3.12'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '3.
|
68
|
+
version: '3.12'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec-json_expectations
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,28 +86,28 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 3.18.1
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 3.18.1
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rubocop
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 1.
|
103
|
+
version: 1.51.0
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 1.
|
110
|
+
version: 1.51.0
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: simplecov
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- ".gitignore"
|
153
153
|
- ".rspec"
|
154
154
|
- ".rubocop.yml"
|
155
|
+
- CHANGELOG.md
|
155
156
|
- Gemfile
|
156
157
|
- LICENSE
|
157
158
|
- README.md
|
@@ -199,7 +200,7 @@ homepage: https://github.com/unleash/unleash-client-ruby
|
|
199
200
|
licenses:
|
200
201
|
- Apache-2.0
|
201
202
|
metadata: {}
|
202
|
-
post_install_message:
|
203
|
+
post_install_message:
|
203
204
|
rdoc_options: []
|
204
205
|
require_paths:
|
205
206
|
- lib
|
@@ -214,8 +215,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
215
|
- !ruby/object:Gem::Version
|
215
216
|
version: '0'
|
216
217
|
requirements: []
|
217
|
-
rubygems_version: 3.3.
|
218
|
-
signing_key:
|
218
|
+
rubygems_version: 3.3.15
|
219
|
+
signing_key:
|
219
220
|
specification_version: 4
|
220
221
|
summary: Unleash feature toggle client.
|
221
222
|
test_files: []
|