flipper-active_record 0.10.2 → 0.11.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/docs/active_record/README.md +2 -1
- data/flipper-active_record.gemspec +13 -13
- data/lib/flipper/adapters/active_record.rb +18 -17
- data/lib/flipper/version.rb +1 -1
- data/lib/generators/flipper/active_record_generator.rb +4 -4
- data/spec/flipper/adapters/active_record_spec.rb +2 -4
- data/test/adapters/active_record_test.rb +2 -4
- data/test/generators/flipper/active_record_generator_test.rb +2 -2
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab2e2560bca689141f6f486224f97abe87ded3a2
|
4
|
+
data.tar.gz: a26ecd4f4a019af72b44c3aa38a93332c3d7b0e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c829cb8be44d1881630fef42431519d547df19bd74fa19ef486d09b287161fc5e8d7fde69f93e0c2be2d9a0eb58300e8d772c4bc7b1f2a4f295453308a1d0779
|
7
|
+
data.tar.gz: 1675a0478c9313f3a7f6e4056cd11d1548e17f4583e8741d44908bd1ce2445f588c0eecda84e2bb106b2073444a2f9c51ef9bb837349c1997da2a7808cad873b
|
@@ -6,6 +6,7 @@ Supported Active Record versions:
|
|
6
6
|
|
7
7
|
* 3.2.x
|
8
8
|
* 4.2.x
|
9
|
+
* 5.0.x
|
9
10
|
|
10
11
|
## Installation
|
11
12
|
|
@@ -23,7 +24,7 @@ Or install it yourself with:
|
|
23
24
|
|
24
25
|
## Usage
|
25
26
|
|
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
|
+
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
28
|
|
28
29
|
$ rails g flipper:active_record
|
29
30
|
|
@@ -1,28 +1,28 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
require File.expand_path('../lib/flipper/version', __FILE__)
|
3
3
|
|
4
|
-
flipper_active_record_files = lambda
|
4
|
+
flipper_active_record_files = lambda do |file|
|
5
5
|
file =~ /active_record/
|
6
|
-
|
6
|
+
end
|
7
7
|
|
8
8
|
Gem::Specification.new do |gem|
|
9
|
-
gem.authors = [
|
10
|
-
gem.email = [
|
11
|
-
gem.summary =
|
12
|
-
gem.description =
|
13
|
-
gem.license =
|
14
|
-
gem.homepage =
|
9
|
+
gem.authors = ['John Nunemaker']
|
10
|
+
gem.email = ['nunemaker@gmail.com']
|
11
|
+
gem.summary = 'ActiveRecord adapter for Flipper'
|
12
|
+
gem.description = 'ActiveRecord adapter for Flipper'
|
13
|
+
gem.license = 'MIT'
|
14
|
+
gem.homepage = 'https://github.com/jnunemaker/flipper'
|
15
15
|
|
16
16
|
extra_files = [
|
17
|
-
|
18
|
-
|
17
|
+
'lib/generators/flipper/templates/migration.rb',
|
18
|
+
'lib/flipper/version.rb',
|
19
19
|
]
|
20
20
|
gem.files = `git ls-files`.split("\n").select(&flipper_active_record_files) + extra_files
|
21
21
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n").select(&flipper_active_record_files)
|
22
|
-
gem.name =
|
23
|
-
gem.require_paths = [
|
22
|
+
gem.name = 'flipper-active_record'
|
23
|
+
gem.require_paths = ['lib']
|
24
24
|
gem.version = Flipper::VERSION
|
25
25
|
|
26
26
|
gem.add_dependency 'flipper', "~> #{Flipper::VERSION}"
|
27
|
-
gem.add_dependency 'activerecord',
|
27
|
+
gem.add_dependency 'activerecord', '>= 3.2', '< 6'
|
28
28
|
end
|
@@ -9,12 +9,12 @@ module Flipper
|
|
9
9
|
|
10
10
|
# Private: Do not use outside of this adapter.
|
11
11
|
class Feature < ::ActiveRecord::Base
|
12
|
-
self.table_name =
|
12
|
+
self.table_name = 'flipper_features'
|
13
13
|
end
|
14
14
|
|
15
15
|
# Private: Do not use outside of this adapter.
|
16
16
|
class Gate < ::ActiveRecord::Base
|
17
|
-
self.table_name =
|
17
|
+
self.table_name = 'flipper_gates'
|
18
18
|
end
|
19
19
|
|
20
20
|
# Public: The name of the adapter.
|
@@ -78,7 +78,7 @@ module Flipper
|
|
78
78
|
|
79
79
|
def get_multi(features)
|
80
80
|
db_gates = @gate_class.where(feature_key: features.map(&:key))
|
81
|
-
grouped_db_gates = db_gates.group_by
|
81
|
+
grouped_db_gates = db_gates.group_by(&:feature_key)
|
82
82
|
result = {}
|
83
83
|
features.each do |feature|
|
84
84
|
result[feature.key] = result_for_feature(feature, grouped_db_gates[feature.key])
|
@@ -90,7 +90,7 @@ module Flipper
|
|
90
90
|
#
|
91
91
|
# feature - The Flipper::Feature for the gate.
|
92
92
|
# gate - The Flipper::Gate to disable.
|
93
|
-
# thing - The Flipper::Type being
|
93
|
+
# thing - The Flipper::Type being enabled for the gate.
|
94
94
|
#
|
95
95
|
# Returns true.
|
96
96
|
def enable(feature, gate, thing)
|
@@ -165,20 +165,21 @@ module Flipper
|
|
165
165
|
db_gates ||= []
|
166
166
|
result = {}
|
167
167
|
feature.gates.each do |gate|
|
168
|
-
result[gate.key] =
|
169
|
-
|
170
|
-
|
171
|
-
db_gate.
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
db_gate.
|
168
|
+
result[gate.key] =
|
169
|
+
case gate.data_type
|
170
|
+
when :boolean
|
171
|
+
if db_gate = db_gates.detect { |db_gate| db_gate.key == gate.key.to_s }
|
172
|
+
db_gate.value
|
173
|
+
end
|
174
|
+
when :integer
|
175
|
+
if db_gate = db_gates.detect { |db_gate| db_gate.key == gate.key.to_s }
|
176
|
+
db_gate.value
|
177
|
+
end
|
178
|
+
when :set
|
179
|
+
db_gates.select { |db_gate| db_gate.key == gate.key.to_s }.map(&:value).to_set
|
180
|
+
else
|
181
|
+
unsupported_data_type gate.data_type
|
176
182
|
end
|
177
|
-
when :set
|
178
|
-
db_gates.select { |db_gate| db_gate.key == gate.key.to_s }.map(&:value).to_set
|
179
|
-
else
|
180
|
-
unsupported_data_type gate.data_type
|
181
|
-
end
|
182
183
|
end
|
183
184
|
result
|
184
185
|
end
|
data/lib/flipper/version.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require 'rails/generators/active_record'
|
2
2
|
|
3
3
|
module Flipper
|
4
4
|
module Generators
|
5
5
|
class ActiveRecordGenerator < ::Rails::Generators::Base
|
6
6
|
include ::Rails::Generators::Migration
|
7
|
-
desc
|
7
|
+
desc 'Generates migration for flipper tables'
|
8
8
|
|
9
|
-
source_paths << File.join(File.dirname(__FILE__),
|
9
|
+
source_paths << File.join(File.dirname(__FILE__), 'templates')
|
10
10
|
|
11
11
|
def create_migration_file
|
12
|
-
migration_template
|
12
|
+
migration_template 'migration.rb', 'db/migrate/create_flipper_tables.rb'
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.next_migration_number(dirname)
|
@@ -11,10 +11,8 @@ RSpec.describe Flipper::Adapters::ActiveRecord do
|
|
11
11
|
subject { described_class.new }
|
12
12
|
|
13
13
|
before(:all) do
|
14
|
-
ActiveRecord::Base.establish_connection(
|
15
|
-
|
16
|
-
database: ":memory:",
|
17
|
-
})
|
14
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3',
|
15
|
+
database: ':memory:')
|
18
16
|
end
|
19
17
|
|
20
18
|
before(:each) do
|
@@ -8,10 +8,8 @@ ActiveRecord::Migration.verbose = false
|
|
8
8
|
class ActiveRecordTest < MiniTest::Test
|
9
9
|
prepend Flipper::Test::SharedAdapterTests
|
10
10
|
|
11
|
-
ActiveRecord::Base.establish_connection(
|
12
|
-
|
13
|
-
database: ":memory:",
|
14
|
-
})
|
11
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3',
|
12
|
+
database: ':memory:')
|
15
13
|
|
16
14
|
def setup
|
17
15
|
@adapter = Flipper::Adapters::ActiveRecord.new
|
@@ -5,12 +5,12 @@ require 'generators/flipper/active_record_generator'
|
|
5
5
|
|
6
6
|
class FlipperActiveRecordGeneratorTest < Rails::Generators::TestCase
|
7
7
|
tests Flipper::Generators::ActiveRecordGenerator
|
8
|
-
destination File.expand_path(
|
8
|
+
destination File.expand_path('../../../../tmp', __FILE__)
|
9
9
|
setup :prepare_destination
|
10
10
|
|
11
11
|
def test_generates_migration
|
12
12
|
run_generator
|
13
|
-
assert_migration
|
13
|
+
assert_migration 'db/migrate/create_flipper_tables.rb', <<-EOM
|
14
14
|
class CreateFlipperTables < ActiveRecord::Migration
|
15
15
|
def self.up
|
16
16
|
create_table :flipper_features do |t|
|
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.11.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-02 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.
|
19
|
+
version: 0.11.0.beta1
|
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.11.0.beta1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,12 +78,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
78
|
version: '0'
|
79
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- - "
|
81
|
+
- - ">"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
83
|
+
version: 1.3.1
|
84
84
|
requirements: []
|
85
85
|
rubyforge_project:
|
86
|
-
rubygems_version: 2.
|
86
|
+
rubygems_version: 2.5.2
|
87
87
|
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: ActiveRecord adapter for Flipper
|