flipper 1.3.0.pre → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/docs/images/banner.jpg +0 -0
- data/lib/flipper/adapters/actor_limit.rb +28 -0
- data/lib/flipper/engine.rb +5 -5
- data/lib/flipper/version.rb +1 -1
- data/lib/flipper.rb +2 -1
- data/spec/flipper/adapters/actor_limit_spec.rb +20 -0
- data/spec/flipper/engine_spec.rb +30 -3
- data/test/adapters/actor_limit_test.rb +20 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 934e0e50f2aea9b4294ed435a780f5eb55ad8b547df9c80f609022b880a4dd9c
|
4
|
+
data.tar.gz: 8799605783af26860795d336a66d511f35b0f644424aca80cd3f81baaadc6475
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0e041360e5d15966dd4f4a39be10616aff35dd56a7491297adce42b8d13d3ba7126feaf2d3798194c72fac73afad7e2355379ff51e40481f4a0ee25c49e6c8a
|
7
|
+
data.tar.gz: c16307b9a21775b1db67e9fd99c72c5206e7b0d6e0324e7625f349228757aea1243be676ba838ac0b853a7a48469fe8536da41085982556c0492ad985daf51ca
|
data/README.md
CHANGED
@@ -112,3 +112,4 @@ We also have a [free plan](https://www.flippercloud.io?utm_source=oss&utm_medium
|
|
112
112
|
| ![@thetimbanks](https://avatars1.githubusercontent.com/u/471801?s=64) | [@thetimbanks](https://github.com/thetimbanks) | ui |
|
113
113
|
| ![@lazebny](https://avatars1.githubusercontent.com/u/6276766?s=64) | [@lazebny](https://github.com/lazebny) | docker |
|
114
114
|
| ![@pagertree](https://avatars.githubusercontent.com/u/24941240?s=64) | [@pagertree](https://github.com/pagertree) | sponsor |
|
115
|
+
| ![@kdaigle](https://avatars.githubusercontent.com/u/2501?s=64) | [@kdaigle](https://github.com/kdaigle) | sponsor |
|
data/docs/images/banner.jpg
CHANGED
Binary file
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Flipper
|
2
|
+
module Adapters
|
3
|
+
class ActorLimit < Wrapper
|
4
|
+
LimitExceeded = Class.new(Flipper::Error)
|
5
|
+
|
6
|
+
attr_reader :limit
|
7
|
+
|
8
|
+
def initialize(adapter, limit = 100)
|
9
|
+
super(adapter)
|
10
|
+
@limit = limit
|
11
|
+
end
|
12
|
+
|
13
|
+
def enable(feature, gate, resource)
|
14
|
+
if gate.is_a?(Flipper::Gates::Actor) && over_limit?(feature)
|
15
|
+
raise LimitExceeded, "Actor limit of #{@limit} exceeded for feature #{feature.key}. See https://www.flippercloud.io/docs/features/actors#limitations"
|
16
|
+
else
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def over_limit?(feature)
|
24
|
+
feature.actors_value.size >= @limit
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/flipper/engine.rb
CHANGED
@@ -25,6 +25,7 @@ module Flipper
|
|
25
25
|
log: ENV.fetch('FLIPPER_LOG', 'true').casecmp('true').zero?,
|
26
26
|
cloud_path: "_flipper",
|
27
27
|
strict: default_strict_value,
|
28
|
+
actor_limit: ENV["FLIPPER_ACTOR_LIMIT"]&.to_i || 100,
|
28
29
|
test_help: Flipper::Typecast.to_boolean(ENV["FLIPPER_TEST_HELP"] || Rails.env.test?),
|
29
30
|
)
|
30
31
|
end
|
@@ -65,13 +66,12 @@ module Flipper
|
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
68
|
-
initializer "flipper.
|
69
|
+
initializer "flipper.adapters", after: :load_config_initializers do |app|
|
69
70
|
flipper = app.config.flipper
|
70
71
|
|
71
|
-
|
72
|
-
Flipper.
|
73
|
-
|
74
|
-
end
|
72
|
+
Flipper.configure do |config|
|
73
|
+
config.use Flipper::Adapters::Strict, flipper.strict if flipper.strict
|
74
|
+
config.use Flipper::Adapters::ActorLimit, flipper.actor_limit if flipper.actor_limit
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
data/lib/flipper/version.rb
CHANGED
data/lib/flipper.rb
CHANGED
@@ -175,10 +175,11 @@ end
|
|
175
175
|
require 'flipper/actor'
|
176
176
|
require 'flipper/adapter'
|
177
177
|
require 'flipper/adapters/wrapper'
|
178
|
+
require 'flipper/adapters/actor_limit'
|
179
|
+
require 'flipper/adapters/instrumented'
|
178
180
|
require 'flipper/adapters/memoizable'
|
179
181
|
require 'flipper/adapters/memory'
|
180
182
|
require 'flipper/adapters/strict'
|
181
|
-
require 'flipper/adapters/instrumented'
|
182
183
|
require 'flipper/adapter_builder'
|
183
184
|
require 'flipper/configuration'
|
184
185
|
require 'flipper/dsl'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "flipper/adapters/actor_limit"
|
2
|
+
|
3
|
+
RSpec.describe Flipper::Adapters::ActorLimit do
|
4
|
+
it_should_behave_like 'a flipper adapter' do
|
5
|
+
let(:limit) { 5 }
|
6
|
+
let(:adapter) { Flipper::Adapters::ActorLimit.new(Flipper::Adapters::Memory.new, limit) }
|
7
|
+
|
8
|
+
subject { adapter }
|
9
|
+
|
10
|
+
describe '#enable' do
|
11
|
+
it "fails when limit exceeded" do
|
12
|
+
5.times { |i| feature.enable Flipper::Actor.new("User;#{i}") }
|
13
|
+
|
14
|
+
expect {
|
15
|
+
feature.enable Flipper::Actor.new("User;6")
|
16
|
+
}.to raise_error(Flipper::Adapters::ActorLimit::LimitExceeded)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/flipper/engine_spec.rb
CHANGED
@@ -53,7 +53,7 @@ RSpec.describe Flipper::Engine do
|
|
53
53
|
ENV['FLIPPER_STRICT'] = 'false'
|
54
54
|
subject
|
55
55
|
expect(config.strict).to eq(false)
|
56
|
-
expect(adapter).
|
56
|
+
expect(adapter).not_to be_instance_of(Flipper::Adapters::Strict)
|
57
57
|
end
|
58
58
|
|
59
59
|
[true, :raise, :warn].each do |value|
|
@@ -69,7 +69,7 @@ RSpec.describe Flipper::Engine do
|
|
69
69
|
initializer { config.strict = false }
|
70
70
|
subject
|
71
71
|
expect(config.strict).to eq(false)
|
72
|
-
expect(adapter).
|
72
|
+
expect(adapter).not_to be_instance_of(Flipper::Adapters::Strict)
|
73
73
|
end
|
74
74
|
|
75
75
|
it "defaults to strict=:warn in RAILS_ENV=development" do
|
@@ -85,7 +85,7 @@ RSpec.describe Flipper::Engine do
|
|
85
85
|
expect(Rails.env).to eq(env)
|
86
86
|
subject
|
87
87
|
expect(config.strict).to eq(false)
|
88
|
-
expect(adapter).
|
88
|
+
expect(adapter).not_to be_instance_of(Flipper::Adapters::Strict)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -337,6 +337,33 @@ RSpec.describe Flipper::Engine do
|
|
337
337
|
expect(ActiveRecord::Base.ancestors).to include(Flipper::Model::ActiveRecord)
|
338
338
|
end
|
339
339
|
|
340
|
+
describe "config.actor_limit" do
|
341
|
+
let(:adapter) do
|
342
|
+
application.initialize!
|
343
|
+
Flipper.adapter.adapter.adapter
|
344
|
+
end
|
345
|
+
|
346
|
+
it "defaults to 100" do
|
347
|
+
expect(adapter).to be_instance_of(Flipper::Adapters::ActorLimit)
|
348
|
+
expect(adapter.limit).to eq(100)
|
349
|
+
end
|
350
|
+
|
351
|
+
it "can be set from FLIPPER_ACTOR_LIMIT env" do
|
352
|
+
ENV["FLIPPER_ACTOR_LIMIT"] = "500"
|
353
|
+
expect(adapter.limit).to eq(500)
|
354
|
+
end
|
355
|
+
|
356
|
+
it "can be set from an initializer" do
|
357
|
+
initializer { config.actor_limit = 99 }
|
358
|
+
expect(adapter.limit).to eq(99)
|
359
|
+
end
|
360
|
+
|
361
|
+
it "can be disabled from an initializer" do
|
362
|
+
initializer { config.actor_limit = false }
|
363
|
+
expect(adapter).not_to be_instance_of(Flipper::Adapters::ActorLimit)
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
340
367
|
# Add app initializer in the same order as config/initializers/*
|
341
368
|
def initializer(&block)
|
342
369
|
application.initializer 'spec', before: :load_config_initializers do
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "flipper/test/shared_adapter_test"
|
3
|
+
require "flipper/adapters/actor_limit"
|
4
|
+
|
5
|
+
class Flipper::Adapters::ActorLimitTest < MiniTest::Test
|
6
|
+
prepend Flipper::Test::SharedAdapterTests
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@memory = Flipper::Adapters::Memory.new
|
10
|
+
@adapter = Flipper::Adapters::ActorLimit.new(@memory, 5)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_enable_fails_when_limit_exceeded
|
14
|
+
5.times { |i| @feature.enable Flipper::Actor.new("User;#{i}") }
|
15
|
+
|
16
|
+
assert_raises Flipper::Adapters::ActorLimit::LimitExceeded do
|
17
|
+
@feature.enable Flipper::Actor.new("User;6")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flipper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.0
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- lib/flipper/actor.rb
|
91
91
|
- lib/flipper/adapter.rb
|
92
92
|
- lib/flipper/adapter_builder.rb
|
93
|
+
- lib/flipper/adapters/actor_limit.rb
|
93
94
|
- lib/flipper/adapters/cache_base.rb
|
94
95
|
- lib/flipper/adapters/dual_write.rb
|
95
96
|
- lib/flipper/adapters/failover.rb
|
@@ -203,6 +204,7 @@ files:
|
|
203
204
|
- spec/flipper/actor_spec.rb
|
204
205
|
- spec/flipper/adapter_builder_spec.rb
|
205
206
|
- spec/flipper/adapter_spec.rb
|
207
|
+
- spec/flipper/adapters/actor_limit_spec.rb
|
206
208
|
- spec/flipper/adapters/dual_write_spec.rb
|
207
209
|
- spec/flipper/adapters/failover_spec.rb
|
208
210
|
- spec/flipper/adapters/failsafe_spec.rb
|
@@ -296,6 +298,7 @@ files:
|
|
296
298
|
- spec/support/fake_udp_socket.rb
|
297
299
|
- spec/support/skippable.rb
|
298
300
|
- spec/support/spec_helpers.rb
|
301
|
+
- test/adapters/actor_limit_test.rb
|
299
302
|
- test/adapters/memory_test.rb
|
300
303
|
- test/adapters/pstore_test.rb
|
301
304
|
- test/test_helper.rb
|
@@ -311,7 +314,7 @@ metadata:
|
|
311
314
|
homepage_uri: https://www.flippercloud.io
|
312
315
|
source_code_uri: https://github.com/flippercloud/flipper
|
313
316
|
bug_tracker_uri: https://github.com/flippercloud/flipper/issues
|
314
|
-
changelog_uri: https://github.com/flippercloud/flipper/releases/tag/v1.3.0
|
317
|
+
changelog_uri: https://github.com/flippercloud/flipper/releases/tag/v1.3.0
|
315
318
|
post_install_message:
|
316
319
|
rdoc_options: []
|
317
320
|
require_paths:
|
@@ -338,6 +341,7 @@ test_files:
|
|
338
341
|
- spec/flipper/actor_spec.rb
|
339
342
|
- spec/flipper/adapter_builder_spec.rb
|
340
343
|
- spec/flipper/adapter_spec.rb
|
344
|
+
- spec/flipper/adapters/actor_limit_spec.rb
|
341
345
|
- spec/flipper/adapters/dual_write_spec.rb
|
342
346
|
- spec/flipper/adapters/failover_spec.rb
|
343
347
|
- spec/flipper/adapters/failsafe_spec.rb
|
@@ -431,6 +435,7 @@ test_files:
|
|
431
435
|
- spec/support/fake_udp_socket.rb
|
432
436
|
- spec/support/skippable.rb
|
433
437
|
- spec/support/spec_helpers.rb
|
438
|
+
- test/adapters/actor_limit_test.rb
|
434
439
|
- test/adapters/memory_test.rb
|
435
440
|
- test/adapters/pstore_test.rb
|
436
441
|
- test/test_helper.rb
|