flipper-active_record 0.20.0 → 0.21.0.rc1

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: de81a55c8c1e6342eb75dfe50aa091e66683ec6f3010fefa25d94ea6a402401b
4
- data.tar.gz: 0accb079f0f7e8d21ef94e9d4973f08d7b9b25689ef142e8a162bd87f325a689
3
+ metadata.gz: 10540b212a4437f26f70a34fb2c172208194cdc610aaf9d7a5cf7f4b8e0f7c49
4
+ data.tar.gz: 5b7f5cb7baa50a1729f230d4ec8962e162e697f5023b73fd6aecd2eb91485fd6
5
5
  SHA512:
6
- metadata.gz: 4d9a7f725bfda72154224599235432fd1b6b4b9478a7e13d2cbbf9265c39cb0fb5a7eb0f0f22b21b5baab2382d649f292746dd773bab8545cbe33c3ceebcbc2e
7
- data.tar.gz: df60418d9825f5ff40ab94167267fd7c2eb7f785ddbb0777cc6a1c2e3dddadde5c0f2fb40346a2f282c2b36d3b5960df350ba319a08c134f23d1ddfce1c04457
6
+ metadata.gz: 38b1110e99668682f51f606f7e08ebde6c03336e7912eef0ecf829ccc784584361b6d1298234739e654b68b18ef6c6ecd1c8cc3102e2d4930b8f60deba0a3e2f
7
+ data.tar.gz: f6ca4e9da379fe7aeb3d3aa58a027f883c30f480ab019a13806f4f378427b742b8ecccf9451f586a46e57b73b3584a4bf7f4d16709af119e17d95c544975c274
@@ -23,30 +23,28 @@ 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
- Once you have created and executed the migration, you can use the active record adapter like so:
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
- adapter = Flipper::Adapters::ActiveRecord.new
35
- flipper = Flipper.new(adapter)
36
- # profit...
36
+ Flipper.configure do |config|
37
+ config.default do
38
+ Flipper.new(Flipper::Adapters::ActiveRecord.new)
39
+ end
40
+ end
37
41
  ```
38
42
 
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
43
  ## Internals
42
44
 
43
45
  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
46
 
45
47
  ```ruby
46
- require 'flipper/adapters/active_record'
47
- adapter = Flipper::Adapters::ActiveRecord.new
48
- flipper = Flipper.new(adapter)
49
-
50
48
  # Register a few groups.
51
49
  Flipper.register(:admins) { |thing| thing.admin? }
52
50
  Flipper.register(:early_access) { |thing| thing.early_access? }
@@ -54,16 +52,16 @@ Flipper.register(:early_access) { |thing| thing.early_access? }
54
52
  # Create a user class that has flipper_id instance method.
55
53
  User = Struct.new(:flipper_id)
56
54
 
57
- flipper[:stats].enable
58
- flipper[:stats].enable_group :admins
59
- flipper[:stats].enable_group :early_access
60
- flipper[:stats].enable_actor User.new('25')
61
- flipper[:stats].enable_actor User.new('90')
62
- flipper[:stats].enable_actor User.new('180')
63
- flipper[:stats].enable_percentage_of_time 15
64
- flipper[:stats].enable_percentage_of_actors 45
55
+ Flipper.enable :stats
56
+ Flipper.enable_group :stats, :admins
57
+ Flipper.enable_group :stats, :early_access
58
+ Flipper.enable_actor :stats, User.new('25')
59
+ Flipper.enable_actor :stats, User.new('90')
60
+ Flipper.enable_actor :stats, User.new('180')
61
+ Flipper.enable_percentage_of_time :stats, 15
62
+ Flipper.enable_percentage_of_actors :stats, 45
65
63
 
66
- flipper[:search].enable
64
+ Flipper.enable :search
67
65
 
68
66
  puts 'all rows in features table'
69
67
  pp Flipper::Adapters::ActiveRecord::Feature.all
@@ -1,10 +1,4 @@
1
- require 'pathname'
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',
@@ -2,4 +2,12 @@ require 'active_support/lazy_load_hooks'
2
2
 
3
3
  ActiveSupport.on_load(:active_record) do
4
4
  require 'flipper/adapters/active_record'
5
+
6
+ Flipper.configure do |config|
7
+ config.default do
8
+ Flipper.new(Flipper::Adapters::ActiveRecord.new)
9
+ end
10
+ end
11
+
12
+ ActiveRecord::Base.include Flipper::Identifier
5
13
  end
@@ -1,3 +1,3 @@
1
1
  module Flipper
2
- VERSION = '0.20.0'.freeze
2
+ VERSION = '0.21.0.rc1'.freeze
3
3
  end
@@ -45,4 +45,22 @@ 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-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
+
62
+ it "defines #flipper_id on AR::Base" do
63
+ expect(ActiveRecord::Base.ancestors).to include(Flipper::Identifier)
64
+ end
65
+ end
48
66
  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.20.0
4
+ version: 0.21.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-20 00:00:00.000000000 Z
11
+ date: 2021-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: flipper
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.20.0
19
+ version: 0.21.0.rc1
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.20.0
26
+ version: 0.21.0.rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -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
@@ -81,15 +80,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
80
  version: '0'
82
81
  required_rubygems_version: !ruby/object:Gem::Requirement
83
82
  requirements:
84
- - - ">="
83
+ - - ">"
85
84
  - !ruby/object:Gem::Version
86
- version: '0'
85
+ version: 1.3.1
87
86
  requirements: []
88
87
  rubygems_version: 3.0.3
89
88
  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
@@ -1,5 +0,0 @@
1
- # This nominally-empty spec ensures that the file "flipper-active_record.rb" can be
2
- # required without error, and guards against regressions of the kind fixed in
3
- # https://github.com/jnunemaker/flipper/pull/437.
4
-
5
- require "flipper-active_record.rb"