flipper-active_record 0.20.4 → 0.22.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/docs/active_record/README.md +16 -20
- data/examples/active_record/ar_setup.rb +1 -7
- data/examples/active_record/basic.rb +4 -7
- data/examples/active_record/internals.rb +10 -12
- data/flipper-active_record.gemspec +1 -1
- data/lib/flipper/adapters/active_record.rb +10 -5
- data/lib/flipper/version.rb +1 -1
- data/spec/flipper/adapters/active_record_spec.rb +14 -0
- metadata +6 -8
- data/spec/flipper/adapters/active_record_requires_spec.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d6c72b579bf974d75846d8b6e149f0790736f16848fe4b0e54a7fa2907262c8
|
4
|
+
data.tar.gz: de4029f2a4a2e6c8a869cfc1c2eb15b65d97ae627844b22fdc0274c4c9bf8e83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf9efccca1b72b1ef7c99b822ad6507a8fb5040f1460b6a2ed4eacc4d62278f72c1419db54a05e0c2ad3348b6dde4d76f011c314b41bc6ffb9f35e07e1f08a18
|
7
|
+
data.tar.gz: b864b6658ef23db29a0f3007fb24b7f641f26d59be006473102b39c2c42e6905ec776df28e2a47e5ab6e8d780f41862aae1a3b7ef9f8a8ac80a693beb7000501
|
@@ -23,30 +23,26 @@ Or install it yourself with:
|
|
23
23
|
|
24
24
|
## Usage
|
25
25
|
|
26
|
-
For your convenience a migration generator is provided to create the necessary migrations for using the active record adapter. By default this generates a migration that will create two database tables - flipper_features and flipper_gates
|
26
|
+
For your convenience a migration generator is provided to create the necessary migrations for using the active record adapter. By default this generates a migration that will create two database tables - `flipper_features` and `flipper_gates`.
|
27
27
|
|
28
28
|
$ rails g flipper:active_record
|
29
29
|
|
30
|
-
|
30
|
+
Note that the active record adapter requires the database tables to be created in order to work; failure to run the migration first will cause an exception to be raised when attempting to initialize the active record adapter.
|
31
|
+
|
32
|
+
Flipper will be configured to use the ActiveRecord adapter when `flipper-active_record` is loaded. But **if you need to customize the adapter**, you can add this to an initializer:
|
31
33
|
|
32
34
|
```ruby
|
33
35
|
require 'flipper/adapters/active_record'
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
Flipper.configure do |config|
|
37
|
+
config.adapter { Flipper::Adapters::ActiveRecord.new }
|
38
|
+
end
|
37
39
|
```
|
38
40
|
|
39
|
-
Note that the active record adapter requires the database tables to be created in order to work; failure to run the migration first will cause an exception to be raised when attempting to initialize the active record adapter.
|
40
|
-
|
41
41
|
## Internals
|
42
42
|
|
43
43
|
Each feature is stored as a row in a features table. Each gate is stored as a row in a gates table, related to the feature by the feature's key.
|
44
44
|
|
45
45
|
```ruby
|
46
|
-
require 'flipper/adapters/active_record'
|
47
|
-
adapter = Flipper::Adapters::ActiveRecord.new
|
48
|
-
flipper = Flipper.new(adapter)
|
49
|
-
|
50
46
|
# Register a few groups.
|
51
47
|
Flipper.register(:admins) { |thing| thing.admin? }
|
52
48
|
Flipper.register(:early_access) { |thing| thing.early_access? }
|
@@ -54,16 +50,16 @@ Flipper.register(:early_access) { |thing| thing.early_access? }
|
|
54
50
|
# Create a user class that has flipper_id instance method.
|
55
51
|
User = Struct.new(:flipper_id)
|
56
52
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
53
|
+
Flipper.enable :stats
|
54
|
+
Flipper.enable_group :stats, :admins
|
55
|
+
Flipper.enable_group :stats, :early_access
|
56
|
+
Flipper.enable_actor :stats, User.new('25')
|
57
|
+
Flipper.enable_actor :stats, User.new('90')
|
58
|
+
Flipper.enable_actor :stats, User.new('180')
|
59
|
+
Flipper.enable_percentage_of_time :stats, 15
|
60
|
+
Flipper.enable_percentage_of_actors :stats, 45
|
65
61
|
|
66
|
-
|
62
|
+
Flipper.enable :search
|
67
63
|
|
68
64
|
puts 'all rows in features table'
|
69
65
|
pp Flipper::Adapters::ActiveRecord::Feature.all
|
@@ -1,10 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'logger'
|
3
|
-
|
4
|
-
root_path = Pathname(__FILE__).dirname.join('..').expand_path
|
5
|
-
lib_path = root_path.join('lib')
|
6
|
-
$:.unshift(lib_path)
|
7
|
-
|
1
|
+
require 'bundler/setup'
|
8
2
|
require 'active_record'
|
9
3
|
ActiveRecord::Base.establish_connection({
|
10
4
|
adapter: 'sqlite3',
|
@@ -3,20 +3,17 @@ require_relative "./ar_setup"
|
|
3
3
|
# Requires the flipper-active_record gem to be installed.
|
4
4
|
require 'flipper/adapters/active_record'
|
5
5
|
|
6
|
-
|
7
|
-
flipper = Flipper.new(adapter)
|
6
|
+
Flipper[:stats].enable
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
if flipper[:stats].enabled?
|
8
|
+
if Flipper[:stats].enabled?
|
12
9
|
puts "Enabled!"
|
13
10
|
else
|
14
11
|
puts "Disabled!"
|
15
12
|
end
|
16
13
|
|
17
|
-
|
14
|
+
Flipper[:stats].disable
|
18
15
|
|
19
|
-
if
|
16
|
+
if Flipper[:stats].enabled?
|
20
17
|
puts "Enabled!"
|
21
18
|
else
|
22
19
|
puts "Disabled!"
|
@@ -2,8 +2,6 @@ require_relative "./ar_setup"
|
|
2
2
|
|
3
3
|
# Requires the flipper-active_record gem to be installed.
|
4
4
|
require 'flipper/adapters/active_record'
|
5
|
-
adapter = Flipper::Adapters::ActiveRecord.new
|
6
|
-
flipper = Flipper.new(adapter)
|
7
5
|
|
8
6
|
# Register a few groups.
|
9
7
|
Flipper.register(:admins) { |thing| thing.admin? }
|
@@ -12,16 +10,16 @@ Flipper.register(:early_access) { |thing| thing.early_access? }
|
|
12
10
|
# Create a user class that has flipper_id instance method.
|
13
11
|
User = Struct.new(:flipper_id)
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
13
|
+
Flipper[:stats].enable
|
14
|
+
Flipper[:stats].enable_group :admins
|
15
|
+
Flipper[:stats].enable_group :early_access
|
16
|
+
Flipper[:stats].enable_actor User.new('25')
|
17
|
+
Flipper[:stats].enable_actor User.new('90')
|
18
|
+
Flipper[:stats].enable_actor User.new('180')
|
19
|
+
Flipper[:stats].enable_percentage_of_time 15
|
20
|
+
Flipper[:stats].enable_percentage_of_actors 45
|
23
21
|
|
24
|
-
|
22
|
+
Flipper[:search].enable
|
25
23
|
|
26
24
|
puts 'all rows in features table'
|
27
25
|
pp Flipper::Adapters::ActiveRecord::Feature.all
|
@@ -105,5 +103,5 @@ pp Flipper::Adapters::ActiveRecord::Gate.all
|
|
105
103
|
puts
|
106
104
|
|
107
105
|
puts 'flipper get of feature'
|
108
|
-
pp adapter.get(
|
106
|
+
pp Flipper.adapter.get(Flipper[:stats])
|
109
107
|
# flipper get of feature
|
@@ -101,11 +101,12 @@ module Flipper
|
|
101
101
|
end
|
102
102
|
|
103
103
|
def get_all
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
104
|
+
features = ::Arel::Table.new(@feature_class.table_name.to_sym)
|
105
|
+
gates = ::Arel::Table.new(@gate_class.table_name.to_sym)
|
106
|
+
rows_query = features.join(gates, Arel::Nodes::OuterJoin)
|
107
|
+
.on(features[:key].eq(gates[:feature_key]))
|
108
|
+
.project(features[:key].as('feature_key'), gates[:key], gates[:value])
|
109
|
+
rows = ::ActiveRecord::Base.connection.select_all rows_query
|
109
110
|
db_gates = rows.map { |row| Gate.new(row) }
|
110
111
|
grouped_db_gates = db_gates.group_by(&:feature_key)
|
111
112
|
result = Hash.new { |hash, key| hash[key] = default_config }
|
@@ -219,3 +220,7 @@ module Flipper
|
|
219
220
|
end
|
220
221
|
end
|
221
222
|
end
|
223
|
+
|
224
|
+
Flipper.configure do |config|
|
225
|
+
config.adapter { Flipper::Adapters::ActiveRecord.new }
|
226
|
+
end
|
data/lib/flipper/version.rb
CHANGED
@@ -45,4 +45,18 @@ RSpec.describe Flipper::Adapters::ActiveRecord do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it_should_behave_like 'a flipper adapter'
|
48
|
+
|
49
|
+
context 'requiring "flipper-active_record"' do
|
50
|
+
before do
|
51
|
+
Flipper.configuration = nil
|
52
|
+
Flipper.instance = nil
|
53
|
+
|
54
|
+
load 'flipper/adapters/active_record.rb'
|
55
|
+
ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Base)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'configures itself' do
|
59
|
+
expect(Flipper.adapter.adapter).to be_a(Flipper::Adapters::ActiveRecord)
|
60
|
+
end
|
61
|
+
end
|
48
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flipper-active_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.22.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: flipper
|
@@ -16,21 +16,21 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.22.0
|
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.
|
26
|
+
version: 0.22.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '4.2'
|
34
34
|
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: '7'
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
43
|
+
version: '4.2'
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '7'
|
@@ -61,7 +61,6 @@ files:
|
|
61
61
|
- lib/flipper/version.rb
|
62
62
|
- lib/generators/flipper/active_record_generator.rb
|
63
63
|
- lib/generators/flipper/templates/migration.erb
|
64
|
-
- spec/flipper/adapters/active_record_requires_spec.rb
|
65
64
|
- spec/flipper/adapters/active_record_spec.rb
|
66
65
|
- test/adapters/active_record_test.rb
|
67
66
|
- test_rails/generators/flipper/active_record_generator_test.rb
|
@@ -90,6 +89,5 @@ signing_key:
|
|
90
89
|
specification_version: 4
|
91
90
|
summary: ActiveRecord adapter for Flipper
|
92
91
|
test_files:
|
93
|
-
- spec/flipper/adapters/active_record_requires_spec.rb
|
94
92
|
- spec/flipper/adapters/active_record_spec.rb
|
95
93
|
- test/adapters/active_record_test.rb
|