unleash 5.0.7 → 5.1.0
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/CHANGELOG.md +6 -0
- data/README.md +112 -73
- data/lib/unleash/feature_toggle.rb +8 -4
- data/lib/unleash/spec_version.rb +1 -1
- data/lib/unleash/variant.rb +5 -3
- data/lib/unleash/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de31279816b192452208e5e6d84af40a0ccee9fc7a7d99d517e48af20f9da21b
|
4
|
+
data.tar.gz: 16405b9809031a5684a9ace670bdcb9606fe74eb7a162c89212131dac5064fe2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e9f734bb3814598f3bfe600f3338c049a974168150cacdb26a90db6a768ff060a89ed647e12e57bb978b74fbc99054f702560b924da57e7322a94365de75a49
|
7
|
+
data.tar.gz: '0274169ed17a2357e080af55265fbe80632fb3acd041e303cd321f844ce0372102a7e8b88c3ab71ba01efcfccb8dbd9eafab37b001b7b66c038a81fb6748b048'
|
data/CHANGELOG.md
CHANGED
@@ -13,6 +13,12 @@ Note: These changes are not considered notable:
|
|
13
13
|
|
14
14
|
## [Unreleased]
|
15
15
|
|
16
|
+
## [5.1.0] - 2024-09-18
|
17
|
+
### Added
|
18
|
+
- feature_enabled in variants (#197)
|
19
|
+
|
20
|
+
### Fixed
|
21
|
+
- fix issue with strategy variant stickiness (#198)
|
16
22
|
|
17
23
|
## [5.0.7] - 2024-09-04
|
18
24
|
### Changed
|
data/README.md
CHANGED
@@ -4,27 +4,51 @@
|
|
4
4
|
[](https://coveralls.io/github/Unleash/unleash-client-ruby?branch=main)
|
5
5
|
[](https://badge.fury.io/rb/unleash)
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
Ruby client for the [Unleash](https://github.com/Unleash/unleash) feature management service.
|
8
|
+
|
9
|
+
- [Supported Ruby Interpreters](#supported-ruby-interpreters)
|
10
|
+
- [Installation](#installation)
|
11
|
+
- [Configure](#configure)
|
12
|
+
- [Dynamic custom HTTP headers](#dynamic-custom-http-headers)
|
13
|
+
- [List of Arguments](#list-of-arguments)
|
14
|
+
- [Usage in a plain Ruby Application](#usage-in-a-plain-ruby-application)
|
15
|
+
- [Usage in a Rails Application](#usage-in-a-rails-application)
|
16
|
+
- [1. Add Initializer](#1-add-initializer)
|
17
|
+
- [1.a Initializer for standard Rails applications](#1a-initializer-for-standard-rails-applications)
|
18
|
+
- [1.b Add Initializer if using Puma in clustered mode](#1b-add-initializer-if-using-puma-in-clustered-mode)
|
19
|
+
- [with `preload_app!`](#with-preload_app)
|
20
|
+
- [without `preload_app!`](#without-preload_app)
|
21
|
+
- [1.c Add Initializer if using Phusion Passenger](#1c-add-initializer-if-using-phusion-passenger)
|
22
|
+
- [1.d Add Initializer hooks when using within Sidekiq](#1d-add-initializer-hooks-when-using-within-sidekiq)
|
23
|
+
- [2. Set Unleash::Context](#2-set-unleashcontext)
|
24
|
+
- [3. Sample usage](#3-sample-usage)
|
25
|
+
- [Variations](#variations)
|
26
|
+
- [Bootstrapping](#bootstrapping)
|
27
|
+
- [Client methods](#client-methods)
|
28
|
+
- [Local test client](#local-test-client)
|
29
|
+
- [Available Strategies](#available-strategies)
|
30
|
+
- [Custom Strategies](#custom-strategies)
|
31
|
+
- [Development](#development)
|
32
|
+
- [Releasing](#releasing)
|
33
|
+
- [Contributing](#contributing)
|
10
34
|
|
11
35
|
## Supported Ruby Interpreters
|
12
36
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
37
|
+
- MRI 3.3
|
38
|
+
- MRI 3.2
|
39
|
+
- MRI 3.1
|
40
|
+
- MRI 3.0
|
41
|
+
- MRI 2.7
|
42
|
+
- MRI 2.6
|
43
|
+
- jruby 9.4
|
44
|
+
- jruby 9.3
|
21
45
|
|
22
46
|
## Installation
|
23
47
|
|
24
48
|
Add this line to your application's Gemfile:
|
25
49
|
|
26
50
|
```ruby
|
27
|
-
gem 'unleash', '~> 5.0
|
51
|
+
gem 'unleash', '~> 5.1.0'
|
28
52
|
```
|
29
53
|
|
30
54
|
And then execute:
|
@@ -38,6 +62,7 @@ Or install it yourself as:
|
|
38
62
|
## Configure
|
39
63
|
|
40
64
|
It is **required** to configure:
|
65
|
+
|
41
66
|
- `url` of the unleash server
|
42
67
|
- `app_name` with the name of the runninng application.
|
43
68
|
- `custom_http_headers` with `{'Authorization': '<API token>'}` when using Unleash v4.0.0 and later.
|
@@ -45,8 +70,8 @@ It is **required** to configure:
|
|
45
70
|
Please substitute the example `'https://unleash.herokuapp.com/api'` for the url of your own instance.
|
46
71
|
|
47
72
|
It is **highly recommended** to configure:
|
48
|
-
- `instance_id` parameter with a unique identifier for the running instance.
|
49
73
|
|
74
|
+
- `instance_id` parameter with a unique identifier for the running instance.
|
50
75
|
|
51
76
|
```ruby
|
52
77
|
Unleash.configure do |config|
|
@@ -63,6 +88,7 @@ UNLEASH = Unleash::Client.new(url: 'https://unleash.herokuapp.com/api', app_name
|
|
63
88
|
```
|
64
89
|
|
65
90
|
## Dynamic custom HTTP headers
|
91
|
+
|
66
92
|
If you need custom HTTP headers that change during the lifetime of the client, the `custom_http_headers` can be given as a `Proc`.
|
67
93
|
|
68
94
|
```ruby
|
@@ -80,32 +106,32 @@ end
|
|
80
106
|
|
81
107
|
#### List of Arguments
|
82
108
|
|
83
|
-
Argument
|
84
|
-
|
85
|
-
`url`
|
86
|
-
`app_name`
|
87
|
-
`instance_id`
|
88
|
-
`environment`
|
89
|
-
`project_name`
|
90
|
-
`refresh_interval`
|
91
|
-
`metrics_interval`
|
92
|
-
`disable_client`
|
93
|
-
`disable_metrics`
|
94
|
-
`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>'}`
|
95
|
-
`timeout`
|
96
|
-
`retry_limit`
|
97
|
-
`backup_file`
|
98
|
-
`logger`
|
99
|
-
`log_level`
|
100
|
-
`bootstrap_config`
|
101
|
-
`strategies`
|
109
|
+
| Argument | Description | Required? | Type | Default Value |
|
110
|
+
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | --------------------------------- | ---------------------------------------------- |
|
111
|
+
| `url` | Unleash server URL. | Y | String | N/A |
|
112
|
+
| `app_name` | Name of your program. | Y | String | N/A |
|
113
|
+
| `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 |
|
114
|
+
| `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` |
|
115
|
+
| `project_name` | Name of the project to retrieve features from. If not set, all feature flags will be retrieved. | N | String | nil |
|
116
|
+
| `refresh_interval` | How often the unleash client should check with the server for configuration changes. | N | Integer | 15 |
|
117
|
+
| `metrics_interval` | How often the unleash client should send metrics to server. | N | Integer | 60 |
|
118
|
+
| `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` |
|
119
|
+
| `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` |
|
120
|
+
| `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 | {} |
|
121
|
+
| `timeout` | How long to wait for the connection to be established or wait in reading state (open_timeout/read_timeout) | N | Integer | 30 |
|
122
|
+
| `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 |
|
123
|
+
| `backup_file` | Filename to store the last known state from the Unleash server. Best to not change this from the default. | N | String | `Dir.tmpdir + "/unleash-#{app_name}-repo.json` |
|
124
|
+
| `logger` | Specify a custom `Logger` class to handle logs for the Unleash client. | N | Class | `Logger.new(STDOUT)` |
|
125
|
+
| `log_level` | Change the log level for the `Logger` class. Constant from `Logger::Severity`. | N | Constant | `Logger::WARN` |
|
126
|
+
| `bootstrap_config` | Bootstrap config on how to loaded data on start-up. This is useful for loading large states on startup without (or before) hitting the network. | N | Unleash::Bootstrap::Configuration | `nil` |
|
127
|
+
| `strategies` | Strategies manager that holds all strategies and allows to add custom strategies | N | Unleash::Strategies | `Unleash::Strategies.new` |
|
102
128
|
|
103
129
|
For a more in-depth look, please see `lib/unleash/configuration.rb`.
|
104
130
|
|
105
|
-
Environment Variable
|
106
|
-
|
107
|
-
`UNLEASH_BOOTSTRAP_FILE` | File to read bootstrap data from
|
108
|
-
`UNLEASH_BOOTSTRAP_URL`
|
131
|
+
| Environment Variable | Description |
|
132
|
+
| ------------------------ | -------------------------------- |
|
133
|
+
| `UNLEASH_BOOTSTRAP_FILE` | File to read bootstrap data from |
|
134
|
+
| `UNLEASH_BOOTSTRAP_URL` | URL to read bootstrap data from |
|
109
135
|
|
110
136
|
## Usage in a plain Ruby Application
|
111
137
|
|
@@ -134,16 +160,21 @@ end
|
|
134
160
|
|
135
161
|
## Usage in a Rails Application
|
136
162
|
|
137
|
-
|
163
|
+
### 1. Add Initializer
|
164
|
+
|
165
|
+
The initializer setup varies depending on whether you’re using a standard setup, Puma in clustered mode, Phusion Passenger, or Sidekiq.
|
166
|
+
|
167
|
+
#### 1.a Initializer for standard Rails applications
|
138
168
|
|
139
169
|
Put in `config/initializers/unleash.rb`:
|
140
170
|
|
141
171
|
```ruby
|
142
172
|
Unleash.configure do |config|
|
143
|
-
config.app_name = Rails.application.class.
|
144
|
-
config.url = '
|
173
|
+
config.app_name = Rails.application.class.module_parent_name
|
174
|
+
config.url = '<YOUR_UNLEASH_URL>'
|
145
175
|
# config.instance_id = "#{Socket.gethostname}"
|
146
176
|
config.logger = Rails.logger
|
177
|
+
config.custom_http_headers = {'Authorization': '<YOUR_API_TOKEN>'}
|
147
178
|
end
|
148
179
|
|
149
180
|
UNLEASH = Unleash::Client.new
|
@@ -151,12 +182,14 @@ UNLEASH = Unleash::Client.new
|
|
151
182
|
# Or if preferred:
|
152
183
|
# Rails.configuration.unleash = Unleash::Client.new
|
153
184
|
```
|
185
|
+
|
154
186
|
For `config.instance_id` use a string with a unique identification for the running instance.
|
155
187
|
For example: it could be the hostname, if you only run one App per host.
|
156
188
|
Or the docker container id, if you are running in docker.
|
157
189
|
If it is not set the client will generate an unique UUID for each execution.
|
158
190
|
|
159
191
|
To have it available in the `rails console` command as well, also add to the file above:
|
192
|
+
|
160
193
|
```ruby
|
161
194
|
Rails.application.console do
|
162
195
|
UNLEASH = Unleash::Client.new
|
@@ -165,9 +198,10 @@ Rails.application.console do
|
|
165
198
|
end
|
166
199
|
```
|
167
200
|
|
168
|
-
#### Add Initializer if using [Puma in clustered mode](https://github.com/puma/puma#clustered-mode)
|
201
|
+
#### 1.b Add Initializer if using [Puma in clustered mode](https://github.com/puma/puma#clustered-mode)
|
169
202
|
|
170
203
|
That is, multiple workers configured in `puma.rb`:
|
204
|
+
|
171
205
|
```ruby
|
172
206
|
workers ENV.fetch("WEB_CONCURRENCY") { 2 }
|
173
207
|
```
|
@@ -175,6 +209,7 @@ workers ENV.fetch("WEB_CONCURRENCY") { 2 }
|
|
175
209
|
##### with `preload_app!`
|
176
210
|
|
177
211
|
Then you may keep the client configuration still in `config/initializers/unleash.rb`:
|
212
|
+
|
178
213
|
```ruby
|
179
214
|
Unleash.configure do |config|
|
180
215
|
config.app_name = Rails.application.class.parent.to_s
|
@@ -205,15 +240,18 @@ end
|
|
205
240
|
##### without `preload_app!`
|
206
241
|
|
207
242
|
By not using `preload_app!`:
|
243
|
+
|
208
244
|
- the `Rails` constant will NOT be available.
|
209
245
|
- but phased restarts will be possible.
|
210
246
|
|
211
247
|
You need to ensure that in `puma.rb`:
|
248
|
+
|
212
249
|
- loading unleash sdk with `require 'unleash'` explicitly, as it will not be pre-loaded.
|
213
250
|
- all parameters must be explicitly set in the `on_worker_boot` block, as `config/initializers/unleash.rb` is not read.
|
214
251
|
- there are no references to `Rails` constant, as that is not yet available.
|
215
252
|
|
216
253
|
Example for `puma.rb`:
|
254
|
+
|
217
255
|
```ruby
|
218
256
|
require 'unleash'
|
219
257
|
|
@@ -237,7 +275,7 @@ end
|
|
237
275
|
|
238
276
|
Note that we also added shutdown hooks in `on_worker_shutdown`, to ensure a clean shutdown.
|
239
277
|
|
240
|
-
#### Add Initializer if using [Phusion Passenger](https://github.com/phusion/passenger)
|
278
|
+
#### 1.c Add Initializer if using [Phusion Passenger](https://github.com/phusion/passenger)
|
241
279
|
|
242
280
|
The unleash client needs to be configured and instantiated inside the `PhusionPassenger.on_event(:starting_worker_process)` code block due to [smart spawning](https://www.phusionpassenger.com/library/indepth/ruby/spawn_methods/#smart-spawning-caveats):
|
243
281
|
|
@@ -259,7 +297,7 @@ PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
|
259
297
|
end
|
260
298
|
```
|
261
299
|
|
262
|
-
#### Add Initializer hooks when using within [Sidekiq](https://github.com/mperham/sidekiq)
|
300
|
+
#### 1.d Add Initializer hooks when using within [Sidekiq](https://github.com/mperham/sidekiq)
|
263
301
|
|
264
302
|
Note that in this case we require that the code block for `Unleash.configure` is set beforehand.
|
265
303
|
For example in `config/initializers/unleash.rb`.
|
@@ -276,7 +314,7 @@ Sidekiq.configure_server do |config|
|
|
276
314
|
end
|
277
315
|
```
|
278
316
|
|
279
|
-
|
317
|
+
### 2. Set Unleash::Context
|
280
318
|
|
281
319
|
Be sure to add the following method and callback in the application controller to have `@unleash_context` set for all requests:
|
282
320
|
|
@@ -297,7 +335,7 @@ Add in `app/controllers/application_controller.rb`:
|
|
297
335
|
|
298
336
|
Or if you see better fit, only in the controllers that you will be using unleash.
|
299
337
|
|
300
|
-
|
338
|
+
### 3. Sample usage
|
301
339
|
|
302
340
|
Then wherever in your application that you need a feature toggle, you can use:
|
303
341
|
|
@@ -367,6 +405,7 @@ end
|
|
367
405
|
```
|
368
406
|
|
369
407
|
Note:
|
408
|
+
|
370
409
|
- The block/lambda/proc can use feature name and context as an arguments.
|
371
410
|
- The client will evaluate the fallback function once per call of `is_enabled()`.
|
372
411
|
Please keep this in mind when creating your fallback function!
|
@@ -375,7 +414,6 @@ Note:
|
|
375
414
|
- If both a `default_value` and `fallback_function` are supplied,
|
376
415
|
the client will define the default value by `OR`ing the default value and the output of the fallback function.
|
377
416
|
|
378
|
-
|
379
417
|
Alternatively by using `if_enabled` (or `if_disabled`) you can send a code block to be executed as a parameter:
|
380
418
|
|
381
419
|
```ruby
|
@@ -386,7 +424,7 @@ end
|
|
386
424
|
|
387
425
|
Note: `if_enabled` (and `if_disabled`) only support `default_value`, but not `fallback_function`.
|
388
426
|
|
389
|
-
|
427
|
+
#### Variations
|
390
428
|
|
391
429
|
If no variant is found in the server, use the fallback variant.
|
392
430
|
|
@@ -401,6 +439,7 @@ puts "variant color is: #{variant.payload.fetch('color')}"
|
|
401
439
|
|
402
440
|
Bootstrap configuration allows the client to be initialized with a predefined set of toggle states.
|
403
441
|
Bootstrapping can be configured by providing a bootstrap configuration when initializing the client.
|
442
|
+
|
404
443
|
```ruby
|
405
444
|
@unleash = Unleash::Client.new(
|
406
445
|
url: 'https://unleash.herokuapp.com/api',
|
@@ -412,13 +451,14 @@ Bootstrapping can be configured by providing a bootstrap configuration when init
|
|
412
451
|
})
|
413
452
|
)
|
414
453
|
```
|
454
|
+
|
415
455
|
The `Bootstrap::Configuration` initializer takes a hash with one of the following options specified:
|
416
456
|
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
457
|
+
- `file_path` - An absolute or relative path to a file containing a JSON string of the response body from the Unleash server. This can also be set though the `UNLEASH_BOOTSTRAP_FILE` environment variable.
|
458
|
+
- `url` - A url pointing to an Unleash server's features endpoint, the code sample above is illustrative. This can also be set though the `UNLEASH_BOOTSTRAP_URL` environment variable.
|
459
|
+
- `url_headers` - Headers for the GET http request to the `url` above. Only used if the `url` parameter is also set. If this option isn't set then the bootstrapper will use the same url headers as the Unleash client.
|
460
|
+
- `data` - A raw JSON string as returned by the Unleash server.
|
461
|
+
- `block` - A lambda containing custom logic if you need it, an example is provided below.
|
422
462
|
|
423
463
|
You should only specify one type of bootstrapping since only one will be invoked and the others will be ignored.
|
424
464
|
The order of preference is as follows:
|
@@ -428,10 +468,10 @@ The order of preference is as follows:
|
|
428
468
|
- If no block bootstrapper exists, select the file bootstrapper from either parameters or the specified environment variable.
|
429
469
|
- If no file bootstrapper exists, then check for a URL bootstrapper from either the parameters or the specified environment variable.
|
430
470
|
|
431
|
-
|
432
471
|
Example usage:
|
433
472
|
|
434
473
|
First saving the toggles locally:
|
474
|
+
|
435
475
|
```shell
|
436
476
|
curl -H 'Authorization: <API token>' -XGET 'https://unleash.herokuapp.com/api' > ./default-toggles.json
|
437
477
|
```
|
@@ -459,17 +499,17 @@ Be aware that the client initializer will block until bootstrapping is complete.
|
|
459
499
|
|
460
500
|
#### Client methods
|
461
501
|
|
462
|
-
Method Name
|
463
|
-
|
464
|
-
`is_enabled?`
|
465
|
-
`enabled?`
|
466
|
-
`if_enabled`
|
467
|
-
`is_disabled?` | Check if feature toggle is to be enabled or not.
|
468
|
-
`disabled?`
|
469
|
-
`if_disabled`
|
470
|
-
`get_variant`
|
471
|
-
`shutdown`
|
472
|
-
`shutdown!`
|
502
|
+
| Method Name | Description | Return Type |
|
503
|
+
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
|
504
|
+
| `is_enabled?` | Check if feature toggle is to be enabled or not. | Boolean |
|
505
|
+
| `enabled?` | Alias to the `is_enabled?` method. But more ruby idiomatic. | Boolean |
|
506
|
+
| `if_enabled` | Run a code block, if a feature is enabled. | `yield` |
|
507
|
+
| `is_disabled?` | Check if feature toggle is to be enabled or not. | Boolean |
|
508
|
+
| `disabled?` | Alias to the `is_disabled?` method. But more ruby idiomatic. | Boolean |
|
509
|
+
| `if_disabled` | Run a code block, if a feature is disabled. | `yield` |
|
510
|
+
| `get_variant` | Get variant for a given feature | `Unleash::Variant` |
|
511
|
+
| `shutdown` | Save metrics to disk, flush metrics to server, and then kill ToggleFetcher and MetricsReporter threads. A safe shutdown. Not really useful in long running applications, like web applications. | nil |
|
512
|
+
| `shutdown!` | Kill ToggleFetcher and MetricsReporter threads immediately. | nil |
|
473
513
|
|
474
514
|
For the full method signatures, please see [client.rb](lib/unleash/client.rb)
|
475
515
|
|
@@ -487,15 +527,15 @@ bundle exec examples/simple.rb
|
|
487
527
|
|
488
528
|
This client comes with the all the required strategies out of the box:
|
489
529
|
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
530
|
+
- ApplicationHostnameStrategy
|
531
|
+
- DefaultStrategy
|
532
|
+
- FlexibleRolloutStrategy
|
533
|
+
- GradualRolloutRandomStrategy
|
534
|
+
- GradualRolloutSessionIdStrategy
|
535
|
+
- GradualRolloutUserIdStrategy
|
536
|
+
- RemoteAddressStrategy
|
537
|
+
- UnknownStrategy
|
538
|
+
- UserWithIdStrategy
|
499
539
|
|
500
540
|
## Custom Strategies
|
501
541
|
|
@@ -546,7 +586,6 @@ Choose a new version number following [Semantic Versioning](https://semver.org/s
|
|
546
586
|
- push git commits and tags to origin and
|
547
587
|
- push the `.gem` file to [rubygems.org](https://rubygems.org)
|
548
588
|
|
549
|
-
|
550
589
|
## Contributing
|
551
590
|
|
552
591
|
Bug reports and pull requests are welcome on GitHub at https://github.com/unleash/unleash-client-ruby.
|
@@ -48,27 +48,31 @@ module Unleash
|
|
48
48
|
|
49
49
|
choice = evaluation_result.enabled? ? :yes : :no
|
50
50
|
Unleash.toggle_metrics.increment_variant(self.name, choice, variant.name) unless Unleash.configuration.disable_metrics
|
51
|
+
|
52
|
+
variant.feature_enabled = evaluation_result.enabled?
|
53
|
+
|
51
54
|
variant
|
52
55
|
end
|
53
56
|
|
54
57
|
def self.disabled_variant
|
55
|
-
Unleash::Variant.new(name: 'disabled', enabled: false)
|
58
|
+
Unleash::Variant.new(name: 'disabled', enabled: false, feature_enabled: false)
|
56
59
|
end
|
57
60
|
|
58
61
|
private
|
59
62
|
|
60
63
|
def resolve_variant(context, evaluation_result, group_id)
|
64
|
+
variant_strategy_stickiness = evaluation_result.strategy&.params.to_h['stickiness'] || 'default'
|
61
65
|
variant_definitions = evaluation_result.strategy&.variant_definitions
|
62
66
|
variant_definitions = self.variant_definitions if variant_definitions.nil? || variant_definitions.empty?
|
63
67
|
return Unleash::FeatureToggle.disabled_variant unless evaluation_result.enabled?
|
64
68
|
return Unleash::FeatureToggle.disabled_variant if sum_variant_defs_weights(variant_definitions) <= 0
|
65
69
|
|
66
70
|
variant_from_override_match(context, variant_definitions) ||
|
67
|
-
variant_from_weights(context, resolve_stickiness(variant_definitions), variant_definitions, group_id)
|
71
|
+
variant_from_weights(context, resolve_stickiness(variant_definitions, variant_strategy_stickiness), variant_definitions, group_id)
|
68
72
|
end
|
69
73
|
|
70
|
-
def resolve_stickiness(variant_definitions)
|
71
|
-
variant_definitions&.map(&:stickiness)&.compact&.first ||
|
74
|
+
def resolve_stickiness(variant_definitions, variant_strategy_stickiness)
|
75
|
+
variant_definitions&.map(&:stickiness)&.compact&.first || variant_strategy_stickiness
|
72
76
|
end
|
73
77
|
|
74
78
|
# only check if it is enabled, do not do metrics
|
data/lib/unleash/spec_version.rb
CHANGED
data/lib/unleash/variant.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Unleash
|
2
2
|
class Variant
|
3
|
-
attr_accessor :name, :enabled, :payload
|
3
|
+
attr_accessor :name, :enabled, :payload, :feature_enabled
|
4
4
|
|
5
5
|
def initialize(params = {})
|
6
6
|
raise ArgumentError, "Variant initializer requires a hash." unless params.is_a?(Hash)
|
@@ -8,16 +8,18 @@ module Unleash
|
|
8
8
|
self.name = params.values_at('name', :name).compact.first
|
9
9
|
self.enabled = params.values_at('enabled', :enabled).compact.first || false
|
10
10
|
self.payload = params.values_at('payload', :payload).compact.first
|
11
|
+
self.feature_enabled = params.values_at('feature_enabled', :feature_enabled).compact.first || false
|
11
12
|
|
12
13
|
raise ArgumentError, "Variant requires a name." if self.name.nil?
|
13
14
|
end
|
14
15
|
|
15
16
|
def to_s
|
16
|
-
"<Variant: name=#{self.name},enabled=#{self.enabled},payload=#{self.payload}>"
|
17
|
+
"<Variant: name=#{self.name},enabled=#{self.enabled},payload=#{self.payload},feature_enabled=#{self.feature_enabled}>"
|
17
18
|
end
|
18
19
|
|
19
20
|
def ==(other)
|
20
|
-
self.name == other.name && self.enabled == other.enabled && self.payload == other.payload
|
21
|
+
self.name == other.name && self.enabled == other.enabled && self.payload == other.payload \
|
22
|
+
&& self.feature_enabled == other.feature_enabled
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
data/lib/unleash/version.rb
CHANGED
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: 5.0
|
4
|
+
version: 5.1.0
|
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: 2024-09-
|
11
|
+
date: 2024-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: murmurhash3
|
@@ -203,7 +203,7 @@ homepage: https://github.com/unleash/unleash-client-ruby
|
|
203
203
|
licenses:
|
204
204
|
- Apache-2.0
|
205
205
|
metadata: {}
|
206
|
-
post_install_message:
|
206
|
+
post_install_message:
|
207
207
|
rdoc_options: []
|
208
208
|
require_paths:
|
209
209
|
- lib
|
@@ -218,8 +218,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
218
|
- !ruby/object:Gem::Version
|
219
219
|
version: '0'
|
220
220
|
requirements: []
|
221
|
-
rubygems_version: 3.
|
222
|
-
signing_key:
|
221
|
+
rubygems_version: 3.4.10
|
222
|
+
signing_key:
|
223
223
|
specification_version: 4
|
224
224
|
summary: Unleash feature toggle client.
|
225
225
|
test_files: []
|