unleash 4.4.2 → 4.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8461b30f4a58518d73731731a7dfbc32041a5a017362319b9d8ba76d2cecb98
4
- data.tar.gz: '06098a3f106f50b0ddad46e17bef57584918ecbefe88486009d95edbdb546550'
3
+ metadata.gz: 910ddad70479cae68918b7400b4ddc6d0c71f9448d8524072c318d6c353c4f52
4
+ data.tar.gz: 1d75ed31736627ea30c2bbc9be7903c9dfa19dc4691c07de885dd87a8eb94c85
5
5
  SHA512:
6
- metadata.gz: ec0644f3bd93de7f75b06e44c059d39ff3ed87af00ee7ca17d1ad3a3e444626f190c4e26863167b116eda85ce0c01196542f8167f4494052fdae9b3e3e09e15c
7
- data.tar.gz: 11764caf8ccd33c757cbd282a5e5f3d6d6b9dc7b70c29c0e9e196b512be3c1baee10abb21279358e7c7001a91b3825d5c42661910695e74e9e1585e2003c9b58
6
+ metadata.gz: aec46ef764fcb138d34baa7c6832ff1865be4dac1f6f004ab928e8447ecde701ec82bf2069c69e62b2404706bf029c1743a3dc2322b5e7409135aba498cdf80e
7
+ data.tar.gz: d1a529a53cbd934c4aae24919352fc670b27b8cb0a9ccb2bde20deafa3eb3adf679e7c49ced246258547f68a400a10a1da214bc07a19e153ffb0af60fcea8961
@@ -10,11 +10,11 @@ jobs:
10
10
  timeout-minutes: 30
11
11
  runs-on: ubuntu-latest
12
12
  steps:
13
- - uses: actions/checkout@v2
13
+ - uses: actions/checkout@v3
14
14
  - name: Set up Ruby
15
15
  uses: ruby/setup-ruby@v1
16
16
  with:
17
- ruby-version: "2.7"
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
@@ -11,6 +11,8 @@ Naming/PredicateName:
11
11
 
12
12
  Metrics/ClassLength:
13
13
  Max: 135
14
+ CountAsOne:
15
+ - 'method_call'
14
16
  Layout/LineLength:
15
17
  Max: 140
16
18
  Metrics/MethodLength:
data/README.md CHANGED
@@ -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` | Environment the program is running on. Could be for example `prod` or `dev`. Not yet in use. | N | String | `default` |
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, but can be useful in when running tests. | N | Boolean | `false` |
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
- if Rails.configuration.unleash.is_disabled? "AwesomeFeature", @unleash_context
325
- puts "AwesomeFeature is enabled"
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 enought coolness and the application has a high enough awesomeness"
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 supports `default_value`, but not `fallback_function`.
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
- 'muCustomStrategy'
509
+ 'myCustomStrategy'
502
510
  end
503
511
 
504
512
  def is_enabled?(params = {}, context = nil)
@@ -513,15 +521,19 @@ end
513
521
 
514
522
  ## Development
515
523
 
516
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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. 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:
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`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
535
+ To install this gem onto your local machine, run `bundle exec rake install`.
536
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
525
537
 
526
538
 
527
539
  ## Contributing
data/bin/console CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
+ require "unleash"
4
5
  require "unleash/client"
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
@@ -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?
@@ -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
- return context.get_by_name(stickiness) unless stickiness == "default"
101
- return context.user_id unless context.user_id.to_s.empty?
102
- return context.session_id unless context.session_id.to_s.empty?
103
- return context.remote_address unless context.remote_address.to_s.empty?
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
@@ -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]['variant'] = {} unless self.features[feature].include? 'variant'
30
- self.features[feature]['variant'][variant] = 0 unless self.features[feature]['variant'].include? variant
31
- self.features[feature]['variant'][variant] += 1
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
 
@@ -1,3 +1,3 @@
1
1
  module Unleash
2
- VERSION = "4.4.2".freeze
2
+ VERSION = "4.4.3".freeze
3
3
  end
@@ -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.6"
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.9"
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.8"
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.2
4
+ version: 4.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renato Arruda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-05 00:00:00.000000000 Z
11
+ date: 2023-06-14 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.6
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.6
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.9'
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.9'
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: '3.8'
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: '3.8'
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.28.2
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.28.2
110
+ version: 1.51.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -214,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  - !ruby/object:Gem::Version
215
215
  version: '0'
216
216
  requirements: []
217
- rubygems_version: 3.3.5
217
+ rubygems_version: 3.4.10
218
218
  signing_key:
219
219
  specification_version: 4
220
220
  summary: Unleash feature toggle client.