unleash 4.4.0 → 4.4.1

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: 5788566712ad3909e6707041673d359a4d9835b59c79bf0e0fac80c7c8a164ed
4
- data.tar.gz: 707f6875e73a10ef24fdce900aa7c179b0762eedda07ce83a41ea5ed76ba494f
3
+ metadata.gz: e7e1d111b5560a8236c52c1b1744f32724fdd0b26d02af16da707efe2869be3e
4
+ data.tar.gz: 402580857880d3508ad7b46afbc47b74c696bb6ad5360a48e4254f35ecd48f05
5
5
  SHA512:
6
- metadata.gz: 5d836f1c130e5db08fdac81f75cb938e93c060f997946ec80bd5819ad098a9b6d7a6d5628f88cd70144899bbe72ac1f5a1e802b4973b6ee0d24eda85e783fab3
7
- data.tar.gz: 69280e8af54ba2613ef3ae17206f0dfbd31a958d2595162dab71dd0d4cf5815d4dc3e023160c1edc1dbcaeea77d2cfd5f2e468af28051fe41b51dd77fae0f689
6
+ metadata.gz: ed380682c17c90cea0d8b79ba7b05f20b053eb20fd3d293f93e3b2356a264ab386fcee3b91b6ec6507965fb23e922f1e9d50cae2bd880973d9111413abda0572
7
+ data.tar.gz: 0ba69ee86b9dc60e65aac73023e9e39c1a93d56579fee7c3f990d4e944259a879ba66058e8614cc41c9dc22a41cc4ab5bf8824e7db24d3e8a5cbc8b5c4fcb4cb
data/.github/stale.yml ADDED
@@ -0,0 +1 @@
1
+ _extends: .github
@@ -28,8 +28,9 @@ jobs:
28
28
  - ubuntu
29
29
  - macos
30
30
  ruby-version:
31
- - jruby-9.2
31
+ - jruby-9.4
32
32
  - jruby-9.3
33
+ - jruby-9.2
33
34
  - 3.1
34
35
  - '3.0'
35
36
  - 2.7
@@ -37,7 +38,7 @@ jobs:
37
38
  - 2.5
38
39
 
39
40
  steps:
40
- - uses: actions/checkout@v2
41
+ - uses: actions/checkout@v3
41
42
  - name: Set up Ruby ${{ matrix.ruby-version }}
42
43
  uses: ruby/setup-ruby@v1
43
44
  with:
data/.rubocop.yml CHANGED
@@ -9,7 +9,7 @@ Naming/PredicateName:
9
9
 
10
10
 
11
11
  Metrics/ClassLength:
12
- Max: 130
12
+ Max: 135
13
13
  Layout/LineLength:
14
14
  Max: 140
15
15
  Metrics/MethodLength:
@@ -22,7 +22,7 @@ Metrics/BlockLength:
22
22
  Metrics/AbcSize:
23
23
  Max: 30
24
24
  Metrics/CyclomaticComplexity:
25
- Max: 9
25
+ Max: 10
26
26
  Metrics/PerceivedComplexity:
27
27
  Max: 10
28
28
 
data/README.md CHANGED
@@ -15,6 +15,7 @@ Leverage the [Unleash Server](https://github.com/Unleash/unleash) for powerful f
15
15
  * MRI 2.7
16
16
  * MRI 2.6
17
17
  * MRI 2.5
18
+ * jruby 9.4
18
19
  * jruby 9.3
19
20
  * jruby 9.2
20
21
 
@@ -23,7 +24,7 @@ Leverage the [Unleash Server](https://github.com/Unleash/unleash) for powerful f
23
24
  Add this line to your application's Gemfile:
24
25
 
25
26
  ```ruby
26
- gem 'unleash', '~> 4.0.0'
27
+ gem 'unleash', '~> 4.4.0'
27
28
  ```
28
29
 
29
30
  And then execute:
@@ -475,7 +476,7 @@ This client comes with the all the required strategies out of the box:
475
476
 
476
477
  ## Custom Strategies
477
478
 
478
- Client allows to add [custom activation strategies](https://docs.getunleash.io/advanced/custom_activation_strategy) using configuration.
479
+ Client allows to add [custom activation strategies](https://docs.getunleash.io/advanced/custom_activation_strategy) using configuration.
479
480
  In order for strategy to work correctly it should support two methods `name` and `is_enabled?`
480
481
 
481
482
  ```ruby
@@ -483,7 +484,7 @@ class MyCustomStrategy
483
484
  def name
484
485
  'muCustomStrategy'
485
486
  end
486
-
487
+
487
488
  def is_enabled?(params = {}, context = nil)
488
489
  true
489
490
  end
@@ -498,6 +499,12 @@ end
498
499
 
499
500
  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.
500
501
 
502
+ 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:
503
+
504
+ `git clone --depth 5 --branch v4.2.2 https://github.com/Unleash/client-specification.git client-specification`
505
+
506
+ After doing this, `rake spec` will also run the client specification tests.
507
+
501
508
  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).
502
509
 
503
510
 
@@ -43,6 +43,7 @@ module Unleash
43
43
 
44
44
  def matches_context?(context)
45
45
  Unleash.logger.debug "Unleash::Constraint matches_context? value: #{self.value} context.get_by_name(#{self.context_name})"
46
+ return false if context.nil?
46
47
 
47
48
  match = matches_constraint?(context)
48
49
  self.inverted ? !match : match
@@ -9,7 +9,7 @@ module Unleash
9
9
 
10
10
  self.app_name = value_for('appName', params, Unleash&.configuration&.app_name)
11
11
  self.environment = value_for('environment', params, Unleash&.configuration&.environment || 'default')
12
- self.user_id = value_for('userId', params)
12
+ self.user_id = value_for('userId', params)&.to_s
13
13
  self.session_id = value_for('sessionId', params)
14
14
  self.remote_address = value_for('remoteAddress', params)
15
15
  self.current_time = value_for('currentTime', params, Time.now.utc.iso8601.to_s)
@@ -37,12 +37,11 @@ module Unleash
37
37
 
38
38
  context = ensure_valid_context(context)
39
39
 
40
- return Unleash::FeatureToggle.disabled_variant unless self.enabled && am_enabled?(context)
41
- return Unleash::FeatureToggle.disabled_variant if sum_variant_defs_weights <= 0
42
-
43
- variant = variant_from_override_match(context) || variant_from_weights(context, resolve_stickiness)
40
+ toggle_enabled = am_enabled?(context)
41
+ variant = resolve_variant(context, toggle_enabled)
44
42
 
45
- Unleash.toggle_metrics.increment_variant(self.name, variant.name) unless Unleash.configuration.disable_metrics
43
+ choice = toggle_enabled ? :yes : :no
44
+ Unleash.toggle_metrics.increment_variant(self.name, choice, variant.name) unless Unleash.configuration.disable_metrics
46
45
  variant
47
46
  end
48
47
 
@@ -52,6 +51,13 @@ module Unleash
52
51
 
53
52
  private
54
53
 
54
+ def resolve_variant(context, toggle_enabled)
55
+ return Unleash::FeatureToggle.disabled_variant unless toggle_enabled
56
+ return Unleash::FeatureToggle.disabled_variant if sum_variant_defs_weights <= 0
57
+
58
+ variant_from_override_match(context) || variant_from_weights(context, resolve_stickiness)
59
+ end
60
+
55
61
  def resolve_stickiness
56
62
  self.variant_definitions&.map(&:stickiness)&.compact&.first || "default"
57
63
  end
@@ -1,33 +1,41 @@
1
1
  module Unleash
2
2
  class Metrics
3
- attr_accessor :features
4
-
5
- # NOTE: no mutexes for features
3
+ attr_accessor :features, :features_lock
6
4
 
7
5
  def initialize
8
6
  self.features = {}
7
+ self.features_lock = Mutex.new
9
8
  end
10
9
 
11
10
  def to_s
12
- self.features.to_json
11
+ self.features_lock.synchronize do
12
+ return self.features.to_json
13
+ end
13
14
  end
14
15
 
15
16
  def increment(feature, choice)
16
17
  raise "InvalidArgument choice must be :yes or :no" unless [:yes, :no].include? choice
17
18
 
18
- self.features[feature] = { yes: 0, no: 0 } unless self.features.include? feature
19
- self.features[feature][choice] += 1
19
+ self.features_lock.synchronize do
20
+ self.features[feature] = { yes: 0, no: 0 } unless self.features.include? feature
21
+ self.features[feature][choice] += 1
22
+ end
20
23
  end
21
24
 
22
- def increment_variant(feature, variant)
23
- self.features[feature] = { yes: 0, no: 0 } unless self.features.include? feature
24
- self.features[feature]['variant'] = {} unless self.features[feature].include? 'variant'
25
- self.features[feature]['variant'][variant] = 0 unless self.features[feature]['variant'].include? variant
26
- self.features[feature]['variant'][variant] += 1
25
+ def increment_variant(feature, choice, variant)
26
+ self.features_lock.synchronize do
27
+ self.features[feature] = { yes: 0, no: 0 } unless self.features.include? feature
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
32
+ end
27
33
  end
28
34
 
29
35
  def reset
30
- self.features = {}
36
+ self.features_lock.synchronize do
37
+ self.features = {}
38
+ end
31
39
  end
32
40
  end
33
41
  end
@@ -1,3 +1,3 @@
1
1
  module Unleash
2
- VERSION = "4.4.0".freeze
2
+ VERSION = "4.4.1".freeze
3
3
  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.0
4
+ version: 4.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renato Arruda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-19 00:00:00.000000000 Z
11
+ date: 2022-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: murmurhash3
@@ -146,6 +146,7 @@ executables:
146
146
  extensions: []
147
147
  extra_rdoc_files: []
148
148
  files:
149
+ - ".github/stale.yml"
149
150
  - ".github/workflows/add-to-project.yml"
150
151
  - ".github/workflows/pull_request.yml"
151
152
  - ".gitignore"