flipper-active_record 0.11.0.beta9 → 0.11.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
  SHA1:
3
- metadata.gz: '093d7f5bb5ea97b06469f6c195268f62b78bb363'
4
- data.tar.gz: bb0203e938669e12652ca430428efd873f73c9d6
3
+ metadata.gz: e6d78e97956403298bc2ef1e7ea2e9790460aaae
4
+ data.tar.gz: ddbda182c4fb85332caada8445e8d0d78f7b77fc
5
5
  SHA512:
6
- metadata.gz: fd7a8a8a7ff4dcbbd7007d39d33f9d2dd933898e99e6086dcbba01936da2ee276c7f435ed41275a55431d49fc101b1432f8721157d2d8d189bbf85b02d21e90b
7
- data.tar.gz: 62857cad99a48ed5beeef9172c31ebb2e7a208e9b1ce4e05369d4a7964e7873e841a1f9e055f41e72db60230308db64802a0e65585296e7fd7d11d06420c9232
6
+ metadata.gz: 2acc8a3002b193d58df21b7ed8a11c05017f62afe07f5eba59a4e589d83ccbd4c45cade944ac24b25b354e3ac50cd51aa907f5f542d5f40ccee3d33ca7507c65
7
+ data.tar.gz: 52eb7c119788e0d16a699a63a094cd10aca7f45bf8250224dba177112f5d2752b5c726770e0c44b07a5fd42a9076e796bae7fd306462ca5031b9a09c6a49f232
@@ -0,0 +1,36 @@
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
+
8
+ require 'active_record'
9
+ ActiveRecord::Base.establish_connection({
10
+ adapter: 'sqlite3',
11
+ database: ':memory:',
12
+ })
13
+
14
+ ActiveRecord::Base.connection.execute <<-SQL
15
+ CREATE TABLE flipper_features (
16
+ id integer PRIMARY KEY,
17
+ key text NOT NULL UNIQUE,
18
+ created_at datetime NOT NULL,
19
+ updated_at datetime NOT NULL
20
+ )
21
+ SQL
22
+
23
+ ActiveRecord::Base.connection.execute <<-SQL
24
+ CREATE TABLE flipper_gates (
25
+ id integer PRIMARY KEY,
26
+ feature_key text NOT NULL,
27
+ key text NOT NULL,
28
+ value text DEFAULT NULL,
29
+ created_at datetime NOT NULL,
30
+ updated_at datetime NOT NULL
31
+ )
32
+ SQL
33
+
34
+ ActiveRecord::Base.connection.execute <<-SQL
35
+ CREATE UNIQUE INDEX index_gates_on_keys_and_value on flipper_gates (feature_key, key, value)
36
+ SQL
@@ -1,18 +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
-
8
- require 'active_record'
9
- ActiveRecord::Base.establish_connection({
10
- adapter: 'sqlite3',
11
- database: ':memory:',
12
- })
13
-
14
- require 'generators/flipper/templates/migration'
15
- CreateFlipperTables.up
1
+ require_relative "./ar_setup"
16
2
 
17
3
  # Requires the flipper-active_record gem to be installed.
18
4
  require 'flipper/adapters/active_record'
@@ -1,20 +1,6 @@
1
- require 'pp'
2
- require 'pathname'
3
- require 'logger'
4
-
5
- root_path = Pathname(__FILE__).dirname.join('..').expand_path
6
- lib_path = root_path.join('lib')
7
- $:.unshift(lib_path)
8
-
9
- require 'active_record'
10
- ActiveRecord::Base.establish_connection({
11
- adapter: 'sqlite3',
12
- database: ':memory:',
13
- })
14
-
15
- require 'generators/flipper/templates/migration'
16
- CreateFlipperTables.up
1
+ require_relative "./ar_setup"
17
2
 
3
+ # Requires the flipper-active_record gem to be installed.
18
4
  require 'flipper/adapters/active_record'
19
5
  adapter = Flipper::Adapters::ActiveRecord.new
20
6
  flipper = Flipper.new(adapter)
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.homepage = 'https://github.com/jnunemaker/flipper'
15
15
 
16
16
  extra_files = [
17
- 'lib/generators/flipper/templates/migration.rb',
17
+ 'lib/generators/flipper/templates/migration.erb',
18
18
  'lib/flipper/version.rb',
19
19
  ]
20
20
  gem.files = `git ls-files`.split("\n").select(&flipper_active_record_files) + extra_files
@@ -46,8 +46,10 @@ module Flipper
46
46
  # Public: Adds a feature to the set of known features.
47
47
  def add(feature)
48
48
  # race condition, but add is only used by enable/disable which happen
49
- # super rarely, so it shouldn't matter in practice
50
- unless @feature_class.where(key: feature.key).first
49
+ # super rarely, so it shouldn't matter in practice; additionally
50
+ # to_a.first is used instead of first because of a Ruby 2.4/Rails 3.2.21
51
+ # CI failure (https://travis-ci.org/jnunemaker/flipper/jobs/297274000).
52
+ unless @feature_class.where(key: feature.key).to_a.first
51
53
  @feature_class.create! { |f| f.key = feature.key }
52
54
  end
53
55
  true
@@ -86,6 +88,21 @@ module Flipper
86
88
  result
87
89
  end
88
90
 
91
+ def get_all
92
+ joins = <<-EOJ
93
+ INNER JOIN #{@feature_class.table_name}
94
+ ON #{@feature_class.table_name}.key = #{@gate_class.table_name}.feature_key
95
+ EOJ
96
+ db_gates = @gate_class.joins(joins).all.to_a
97
+ grouped_db_gates = db_gates.group_by(&:feature_key)
98
+ result = Hash.new { |hash, key| hash[key] = default_config }
99
+ features = grouped_db_gates.keys.map { |key| Flipper::Feature.new(key, self) }
100
+ features.each do |feature|
101
+ result[feature.key] = result_for_feature(feature, grouped_db_gates[feature.key])
102
+ end
103
+ result
104
+ end
105
+
89
106
  # Public: Enables a gate for a given thing.
90
107
  #
91
108
  # feature - The Flipper::Feature for the gate.
@@ -1,3 +1,3 @@
1
1
  module Flipper
2
- VERSION = '0.11.0.beta9'.freeze
2
+ VERSION = '0.11.0.rc1'.freeze
3
3
  end
@@ -8,12 +8,27 @@ module Flipper
8
8
 
9
9
  source_paths << File.join(File.dirname(__FILE__), 'templates')
10
10
 
11
+ def self.next_migration_number(dirname)
12
+ ::ActiveRecord::Generators::Base.next_migration_number(dirname)
13
+ end
14
+
15
+ def self.migration_version
16
+ "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" if rails5?
17
+ end
18
+
19
+ def self.rails5?
20
+ Rails.version.start_with?('5')
21
+ end
22
+
11
23
  def create_migration_file
12
- migration_template 'migration.rb', 'db/migrate/create_flipper_tables.rb'
24
+ options = {
25
+ migration_version: migration_version,
26
+ }
27
+ migration_template 'migration.erb', 'db/migrate/create_flipper_tables.rb', options
13
28
  end
14
29
 
15
- def self.next_migration_number(dirname)
16
- ::ActiveRecord::Generators::Base.next_migration_number(dirname)
30
+ def migration_version
31
+ self.class.migration_version
17
32
  end
18
33
  end
19
34
  end
@@ -1,4 +1,4 @@
1
- class CreateFlipperTables < ActiveRecord::Migration
1
+ class CreateFlipperTables < ActiveRecord::Migration<%= migration_version %>
2
2
  def self.up
3
3
  create_table :flipper_features do |t|
4
4
  t.string :key, null: false
@@ -5,8 +5,6 @@ require 'flipper/spec/shared_adapter_specs'
5
5
  # Turn off migration logging for specs
6
6
  ActiveRecord::Migration.verbose = false
7
7
 
8
- require 'generators/flipper/templates/migration'
9
-
10
8
  RSpec.describe Flipper::Adapters::ActiveRecord do
11
9
  subject { described_class.new }
12
10
 
@@ -16,11 +14,34 @@ RSpec.describe Flipper::Adapters::ActiveRecord do
16
14
  end
17
15
 
18
16
  before(:each) do
19
- CreateFlipperTables.up
17
+ ActiveRecord::Base.connection.execute <<-SQL
18
+ CREATE TABLE flipper_features (
19
+ id integer PRIMARY KEY,
20
+ key text NOT NULL UNIQUE,
21
+ created_at datetime NOT NULL,
22
+ updated_at datetime NOT NULL
23
+ )
24
+ SQL
25
+
26
+ ActiveRecord::Base.connection.execute <<-SQL
27
+ CREATE TABLE flipper_gates (
28
+ id integer PRIMARY KEY,
29
+ feature_key text NOT NULL,
30
+ key text NOT NULL,
31
+ value text DEFAULT NULL,
32
+ created_at datetime NOT NULL,
33
+ updated_at datetime NOT NULL
34
+ )
35
+ SQL
36
+
37
+ ActiveRecord::Base.connection.execute <<-SQL
38
+ CREATE UNIQUE INDEX index_gates_on_keys_and_value on flipper_gates (feature_key, key, value)
39
+ SQL
20
40
  end
21
41
 
22
42
  after(:each) do
23
- CreateFlipperTables.down
43
+ ActiveRecord::Base.connection.execute("DROP table IF EXISTS `flipper_features`")
44
+ ActiveRecord::Base.connection.execute("DROP table IF EXISTS `flipper_gates`")
24
45
  end
25
46
 
26
47
  it_should_behave_like 'a flipper adapter'
@@ -1,6 +1,5 @@
1
1
  require 'test_helper'
2
2
  require 'flipper/adapters/active_record'
3
- require 'generators/flipper/templates/migration'
4
3
 
5
4
  # Turn off migration logging for specs
6
5
  ActiveRecord::Migration.verbose = false
@@ -13,10 +12,34 @@ class ActiveRecordTest < MiniTest::Test
13
12
 
14
13
  def setup
15
14
  @adapter = Flipper::Adapters::ActiveRecord.new
16
- CreateFlipperTables.up
15
+
16
+ ActiveRecord::Base.connection.execute <<-SQL
17
+ CREATE TABLE flipper_features (
18
+ id integer PRIMARY KEY,
19
+ key text NOT NULL UNIQUE,
20
+ created_at datetime NOT NULL,
21
+ updated_at datetime NOT NULL
22
+ )
23
+ SQL
24
+
25
+ ActiveRecord::Base.connection.execute <<-SQL
26
+ CREATE TABLE flipper_gates (
27
+ id integer PRIMARY KEY,
28
+ feature_key text NOT NULL,
29
+ key text NOT NULL,
30
+ value text DEFAULT NULL,
31
+ created_at datetime NOT NULL,
32
+ updated_at datetime NOT NULL
33
+ )
34
+ SQL
35
+
36
+ ActiveRecord::Base.connection.execute <<-SQL
37
+ CREATE UNIQUE INDEX index_gates_on_keys_and_value on flipper_gates (feature_key, key, value)
38
+ SQL
17
39
  end
18
40
 
19
41
  def teardown
20
- CreateFlipperTables.down
42
+ ActiveRecord::Base.connection.execute("DROP table IF EXISTS `flipper_features`")
43
+ ActiveRecord::Base.connection.execute("DROP table IF EXISTS `flipper_gates`")
21
44
  end
22
45
  end
@@ -10,8 +10,13 @@ class FlipperActiveRecordGeneratorTest < Rails::Generators::TestCase
10
10
 
11
11
  def test_generates_migration
12
12
  run_generator
13
+ migration_version = if Rails::VERSION::MAJOR.to_i < 5
14
+ ""
15
+ else
16
+ "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
17
+ end
13
18
  assert_migration 'db/migrate/create_flipper_tables.rb', <<-EOM
14
- class CreateFlipperTables < ActiveRecord::Migration
19
+ class CreateFlipperTables < ActiveRecord::Migration#{migration_version}
15
20
  def self.up
16
21
  create_table :flipper_features do |t|
17
22
  t.string :key, null: false
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.11.0.beta9
4
+ version: 0.11.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: 2017-10-28 00:00:00.000000000 Z
11
+ date: 2017-11-04 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.11.0.beta9
19
+ version: 0.11.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.11.0.beta9
26
+ version: 0.11.0.rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,7 @@ extensions: []
52
52
  extra_rdoc_files: []
53
53
  files:
54
54
  - docs/active_record/README.md
55
+ - examples/active_record/ar_setup.rb
55
56
  - examples/active_record/basic.rb
56
57
  - examples/active_record/internals.rb
57
58
  - flipper-active_record.gemspec
@@ -59,7 +60,7 @@ files:
59
60
  - lib/flipper/adapters/active_record.rb
60
61
  - lib/flipper/version.rb
61
62
  - lib/generators/flipper/active_record_generator.rb
62
- - lib/generators/flipper/templates/migration.rb
63
+ - lib/generators/flipper/templates/migration.erb
63
64
  - spec/flipper/adapters/active_record_spec.rb
64
65
  - test/adapters/active_record_test.rb
65
66
  - test/generators/flipper/active_record_generator_test.rb