flipper-active_record 1.3.3 → 1.3.4
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/examples/active_record/ar_setup.rb +15 -0
- data/examples/active_record/group_migration.rb +68 -0
- data/lib/flipper/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae15abe1a25ef415ec5f7783b24192ae52cbf86b6d8e8026a7b23d3182db2ea3
|
4
|
+
data.tar.gz: 92c793efbd0539545f73d363f61df2f3a43d949aafb0bb303ecb5d8a747e660a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a01ae2b84eea1af1a46ed86a0727a38418ec88682fddf0e8829e340f39e368adf7e3451e07b05efc423d874cc6bf70910bfc7afe61267db84c6e8ef90d6f1764
|
7
|
+
data.tar.gz: 280adedbab88143432826be99f65e17673f9bc0012ddb4c89392b32c6dd2c6ec9ce71a68bf1f79dce2347a631afc5d0f3804092ddbd2d6ef6906fb2af6142534
|
@@ -28,3 +28,18 @@ SQL
|
|
28
28
|
ActiveRecord::Base.connection.execute <<-SQL
|
29
29
|
CREATE UNIQUE INDEX index_gates_on_keys_and_value on flipper_gates (feature_key, key, value)
|
30
30
|
SQL
|
31
|
+
|
32
|
+
ActiveRecord::Base.connection.execute <<-SQL
|
33
|
+
CREATE TABLE users (
|
34
|
+
id integer PRIMARY KEY,
|
35
|
+
name string NOT NULL,
|
36
|
+
influencer boolean,
|
37
|
+
created_at datetime NOT NULL,
|
38
|
+
updated_at datetime NOT NULL
|
39
|
+
)
|
40
|
+
SQL
|
41
|
+
|
42
|
+
require 'flipper/model/active_record'
|
43
|
+
class User < ActiveRecord::Base
|
44
|
+
include Flipper::Model::ActiveRecord
|
45
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# This is an example script that shows how to migrate from a bunch of individual
|
2
|
+
# actors to a group. Should be useful for those who have ended up with large
|
3
|
+
# actor sets and want to slim them down for performance reasons.
|
4
|
+
|
5
|
+
require_relative "./ar_setup"
|
6
|
+
require 'flipper/adapters/active_record'
|
7
|
+
require 'active_support/all'
|
8
|
+
|
9
|
+
# 1. enable feature for 100 actors, make 80 influencers
|
10
|
+
users = 100.times.map do |n|
|
11
|
+
influencer = n < 80 ? true : false
|
12
|
+
user = User.create(name: n, influencer: influencer)
|
13
|
+
Flipper.enable :stats, user
|
14
|
+
user
|
15
|
+
end
|
16
|
+
|
17
|
+
# check enabled, should all be because individual actors are enabled
|
18
|
+
print 'Should be [[true, 100]]: '
|
19
|
+
print users.group_by { |user| Flipper.enabled?(:stats, user) }.map { |result, users| [result, users.size]}
|
20
|
+
puts
|
21
|
+
|
22
|
+
# 2. register a group so flipper knows what to do with it
|
23
|
+
Flipper.register(:influencers) do |actor, context|
|
24
|
+
actor.respond_to?(:influencer) && actor.influencer
|
25
|
+
end
|
26
|
+
|
27
|
+
# 3. enable group for feature, THIS IS IMPORTANT
|
28
|
+
Flipper.enable :stats, :influencers
|
29
|
+
|
30
|
+
# check enabled again, should all still be true because individual actors are
|
31
|
+
# enabled, but also the group gate would return true for 80 influencers. At this
|
32
|
+
# point, it's kind of double true but flipper just cares if any gate returns true.
|
33
|
+
print 'Should be [[true, 100]]: '
|
34
|
+
print users.group_by { |user| Flipper.enabled?(:stats, user) }.map { |result, users| [result, users.size]}
|
35
|
+
puts
|
36
|
+
|
37
|
+
# 4. now we want to clean up the actors that are covered by the group to slim down
|
38
|
+
# the actor set size. So we loop through actors and remove them if group returns
|
39
|
+
# true for the provided actor and context.
|
40
|
+
Flipper[:stats].actors_value.each do |flipper_id|
|
41
|
+
# Hydrate the flipper_id into an active record object. Modify this based on
|
42
|
+
# your flipper_id's if you use anything other than active record models and
|
43
|
+
# the default flipper_id provided by flipper.
|
44
|
+
class_name, id = flipper_id.split(';')
|
45
|
+
klass = class_name.constantize
|
46
|
+
user = klass.find(id)
|
47
|
+
|
48
|
+
# if user is in group then disable for actor because they'll still get the feature
|
49
|
+
context = Flipper::FeatureCheckContext.new(
|
50
|
+
feature_name: :stats,
|
51
|
+
values: Flipper[:stats].gate_values,
|
52
|
+
actors: [Flipper::Types::Actor.wrap(user)]
|
53
|
+
)
|
54
|
+
|
55
|
+
if Flipper::Gates::Group.new.open?(context)
|
56
|
+
Flipper.disable(:stats, user)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# check enabled again, should be the same result as previous checks
|
61
|
+
print 'Should be [[true, 100]]: '
|
62
|
+
print users.group_by { |user| Flipper.enabled?(:stats, user) }.map { |result, users| [result, users.size]}
|
63
|
+
puts
|
64
|
+
|
65
|
+
puts "Actors enabled: #{Flipper[:stats].actors_value.size}"
|
66
|
+
puts "Groups enabled: #{Flipper[:stats].groups_value.size}"
|
67
|
+
|
68
|
+
puts "All actors that could be migrated to groups were migrated. Yay!"
|
data/lib/flipper/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flipper-active_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-03-03 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: flipper
|
@@ -15,14 +15,14 @@ dependencies:
|
|
15
15
|
requirements:
|
16
16
|
- - "~>"
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version: 1.3.
|
18
|
+
version: 1.3.4
|
19
19
|
type: :runtime
|
20
20
|
prerelease: false
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
22
22
|
requirements:
|
23
23
|
- - "~>"
|
24
24
|
- !ruby/object:Gem::Version
|
25
|
-
version: 1.3.
|
25
|
+
version: 1.3.4
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: activerecord
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- examples/active_record/ar_setup.rb
|
55
55
|
- examples/active_record/basic.rb
|
56
56
|
- examples/active_record/cached.rb
|
57
|
+
- examples/active_record/group_migration.rb
|
57
58
|
- examples/active_record/internals.rb
|
58
59
|
- flipper-active_record.gemspec
|
59
60
|
- lib/flipper-active_record.rb
|
@@ -72,7 +73,7 @@ metadata:
|
|
72
73
|
homepage_uri: https://www.flippercloud.io
|
73
74
|
source_code_uri: https://github.com/flippercloud/flipper
|
74
75
|
bug_tracker_uri: https://github.com/flippercloud/flipper/issues
|
75
|
-
changelog_uri: https://github.com/flippercloud/flipper/releases/tag/v1.3.
|
76
|
+
changelog_uri: https://github.com/flippercloud/flipper/releases/tag/v1.3.4
|
76
77
|
funding_uri: https://github.com/sponsors/flippercloud
|
77
78
|
rdoc_options: []
|
78
79
|
require_paths:
|