flipper-sequel 0.10.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 +7 -0
- data/docs/sequel/README.md +98 -0
- data/examples/sequel/basic.rb +33 -0
- data/examples/sequel/internals.rb +63 -0
- data/flipper-sequel.gemspec +25 -0
- data/lib/flipper-sequel.rb +1 -0
- data/lib/flipper/adapters/sequel.rb +167 -0
- data/lib/flipper/version.rb +3 -0
- data/lib/generators/flipper/templates/sequel_migration.rb +24 -0
- data/spec/flipper/adapters/sequel_spec.rb +31 -0
- data/test/adapters/sequel_test.rb +31 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: df1b81f95974a8a3031d8eec88dab17e58a431d6
|
4
|
+
data.tar.gz: ce60bc0a29724c2ffe4792cddc7dd5288846674d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8ba64fd21841b4a4aa4df29b065d7b3bfbc06948d83d3645a6fee421401847f9c8ac70864c264983db625bd8cd441301edde1a4c62b517bc700248e537028266
|
7
|
+
data.tar.gz: ce08d6d9f7f6cc3f8686fa1f29b803f5afbb61a3b75f87a11facc91fdd675a79e5017aa0979967366f71bb9b4dabafa028d6b8e2c99fbb465c43676ca760f04a
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# Flipper Sequel
|
2
|
+
|
3
|
+
A Sequel adapter for [Flipper](https://github.com/jnunemaker/flipper).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'flipper-sequel'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself with:
|
16
|
+
|
17
|
+
$ gem install flipper-sequel
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
For your convenience, a sequel migration is provided to create the necessary tables. This migration will create two database tables - flipper_features and flipper_gates.
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'generators/flipper/templates/sequel_migration'
|
25
|
+
CreateFlipperTablesSequel.new(Sequel::Model.db).up
|
26
|
+
```
|
27
|
+
|
28
|
+
Once you have created and executed the migration, you can use the sequel adapter like so:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'flipper/adapters/sequel'
|
32
|
+
adapter = Flipper::Adapters::Sequel.new
|
33
|
+
flipper = Flipper.new(adapter)
|
34
|
+
# profit...
|
35
|
+
```
|
36
|
+
|
37
|
+
## Internals
|
38
|
+
|
39
|
+
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.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'flipper/adapters/sequel'
|
43
|
+
adapter = Flipper::Adapters::Sequel.new
|
44
|
+
flipper = Flipper.new(adapter)
|
45
|
+
|
46
|
+
# Register a few groups.
|
47
|
+
Flipper.register(:admins) { |thing| thing.admin? }
|
48
|
+
Flipper.register(:early_access) { |thing| thing.early_access? }
|
49
|
+
|
50
|
+
# Create a user class that has flipper_id instance method.
|
51
|
+
User = Struct.new(:flipper_id)
|
52
|
+
|
53
|
+
flipper[:stats].enable
|
54
|
+
flipper[:stats].enable_group :admins
|
55
|
+
flipper[:stats].enable_group :early_access
|
56
|
+
flipper[:stats].enable_actor User.new('25')
|
57
|
+
flipper[:stats].enable_actor User.new('90')
|
58
|
+
flipper[:stats].enable_actor User.new('180')
|
59
|
+
flipper[:stats].enable_percentage_of_time 15
|
60
|
+
flipper[:stats].enable_percentage_of_actors 45
|
61
|
+
|
62
|
+
flipper[:search].enable
|
63
|
+
|
64
|
+
puts 'all rows in features table'
|
65
|
+
pp Flipper::Adapters::Sequel::Feature.all
|
66
|
+
#[#<Flipper::Adapters::Sequel::Feature @values={:key=>"stats", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>,
|
67
|
+
# #<Flipper::Adapters::Sequel::Feature @values={:key=>"search", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>]
|
68
|
+
puts
|
69
|
+
|
70
|
+
puts 'all rows in gates table'
|
71
|
+
pp Flipper::Adapters::Sequel::Gate.all
|
72
|
+
# [#<Flipper::Adapters::Sequel::Gate @values={:feature_key=>"stats", :key=>"boolean", :value=>"true", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>,
|
73
|
+
# #<Flipper::Adapters::Sequel::Gate @values={:feature_key=>"stats", :key=>"groups", :value=>"admins", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>,
|
74
|
+
# #<Flipper::Adapters::Sequel::Gate @values={:feature_key=>"stats", :key=>"groups", :value=>"early_access", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>,
|
75
|
+
# #<Flipper::Adapters::Sequel::Gate @values={:feature_key=>"stats", :key=>"actors", :value=>"25", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>,
|
76
|
+
# #<Flipper::Adapters::Sequel::Gate @values={:feature_key=>"stats", :key=>"actors", :value=>"90", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>,
|
77
|
+
# #<Flipper::Adapters::Sequel::Gate @values={:feature_key=>"stats", :key=>"actors", :value=>"180", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>,
|
78
|
+
# #<Flipper::Adapters::Sequel::Gate @values={:feature_key=>"stats", :key=>"percentage_of_time", :value=>"15", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>,
|
79
|
+
# #<Flipper::Adapters::Sequel::Gate @values={:feature_key=>"stats", :key=>"percentage_of_actors", :value=>"45", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>,
|
80
|
+
# #<Flipper::Adapters::Sequel::Gate @values={:feature_key=>"search", :key=>"boolean", :value=>"true", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>]
|
81
|
+
puts
|
82
|
+
|
83
|
+
puts 'flipper get of feature'
|
84
|
+
pp adapter.get(flipper[:stats])
|
85
|
+
# {:boolean=>"true",
|
86
|
+
# :groups=>#<Set: {"admins", "early_access"}>,
|
87
|
+
# :actors=>#<Set: {"180", "25", "90"}>,
|
88
|
+
# :percentage_of_actors=>"45",
|
89
|
+
# :percentage_of_time=>"15"}
|
90
|
+
```
|
91
|
+
|
92
|
+
## Contributing
|
93
|
+
|
94
|
+
1. Fork it
|
95
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
96
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
97
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
98
|
+
5. Create new Pull Request
|
@@ -0,0 +1,33 @@
|
|
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 'sequel'
|
9
|
+
Sequel::Model.db = Sequel.sqlite(':memory:')
|
10
|
+
Sequel.extension :migration, :core_extensions
|
11
|
+
|
12
|
+
require 'generators/flipper/templates/sequel_migration'
|
13
|
+
CreateFlipperTablesSequel.new(Sequel::Model.db).up
|
14
|
+
|
15
|
+
require 'flipper/adapters/sequel'
|
16
|
+
adapter = Flipper::Adapters::Sequel.new
|
17
|
+
flipper = Flipper.new(adapter)
|
18
|
+
|
19
|
+
flipper[:stats].enable
|
20
|
+
|
21
|
+
if flipper[:stats].enabled?
|
22
|
+
puts "Enabled!"
|
23
|
+
else
|
24
|
+
puts "Disabled!"
|
25
|
+
end
|
26
|
+
|
27
|
+
flipper[:stats].disable
|
28
|
+
|
29
|
+
if flipper[:stats].enabled?
|
30
|
+
puts "Enabled!"
|
31
|
+
else
|
32
|
+
puts "Disabled!"
|
33
|
+
end
|
@@ -0,0 +1,63 @@
|
|
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 'sequel'
|
10
|
+
Sequel::Model.db = Sequel.sqlite(':memory:')
|
11
|
+
Sequel.extension :migration, :core_extensions
|
12
|
+
|
13
|
+
require 'generators/flipper/templates/sequel_migration'
|
14
|
+
CreateFlipperTablesSequel.new(Sequel::Model.db).up
|
15
|
+
|
16
|
+
require 'flipper/adapters/sequel'
|
17
|
+
adapter = Flipper::Adapters::Sequel.new
|
18
|
+
flipper = Flipper.new(adapter)
|
19
|
+
|
20
|
+
# Register a few groups.
|
21
|
+
Flipper.register(:admins) { |thing| thing.admin? }
|
22
|
+
Flipper.register(:early_access) { |thing| thing.early_access? }
|
23
|
+
|
24
|
+
# Create a user class that has flipper_id instance method.
|
25
|
+
User = Struct.new(:flipper_id)
|
26
|
+
|
27
|
+
flipper[:stats].enable
|
28
|
+
flipper[:stats].enable_group :admins
|
29
|
+
flipper[:stats].enable_group :early_access
|
30
|
+
flipper[:stats].enable_actor User.new('25')
|
31
|
+
flipper[:stats].enable_actor User.new('90')
|
32
|
+
flipper[:stats].enable_actor User.new('180')
|
33
|
+
flipper[:stats].enable_percentage_of_time 15
|
34
|
+
flipper[:stats].enable_percentage_of_actors 45
|
35
|
+
|
36
|
+
flipper[:search].enable
|
37
|
+
|
38
|
+
puts 'all rows in features table'
|
39
|
+
pp Flipper::Adapters::Sequel::Feature.all
|
40
|
+
#[#<Flipper::Adapters::Sequel::Feature @values={:key=>"stats", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>,
|
41
|
+
# #<Flipper::Adapters::Sequel::Feature @values={:key=>"search", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>]
|
42
|
+
puts
|
43
|
+
|
44
|
+
puts 'all rows in gates table'
|
45
|
+
pp Flipper::Adapters::Sequel::Gate.all
|
46
|
+
# [#<Flipper::Adapters::Sequel::Gate @values={:feature_key=>"stats", :key=>"boolean", :value=>"true", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>,
|
47
|
+
# #<Flipper::Adapters::Sequel::Gate @values={:feature_key=>"stats", :key=>"groups", :value=>"admins", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>,
|
48
|
+
# #<Flipper::Adapters::Sequel::Gate @values={:feature_key=>"stats", :key=>"groups", :value=>"early_access", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>,
|
49
|
+
# #<Flipper::Adapters::Sequel::Gate @values={:feature_key=>"stats", :key=>"actors", :value=>"25", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>,
|
50
|
+
# #<Flipper::Adapters::Sequel::Gate @values={:feature_key=>"stats", :key=>"actors", :value=>"90", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>,
|
51
|
+
# #<Flipper::Adapters::Sequel::Gate @values={:feature_key=>"stats", :key=>"actors", :value=>"180", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>,
|
52
|
+
# #<Flipper::Adapters::Sequel::Gate @values={:feature_key=>"stats", :key=>"percentage_of_time", :value=>"15", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>,
|
53
|
+
# #<Flipper::Adapters::Sequel::Gate @values={:feature_key=>"stats", :key=>"percentage_of_actors", :value=>"45", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>,
|
54
|
+
# #<Flipper::Adapters::Sequel::Gate @values={:feature_key=>"search", :key=>"boolean", :value=>"true", :created_at=>2016-11-19 13:57:48 -0500, :updated_at=>2016-11-19 13:57:48 -0500}>]
|
55
|
+
puts
|
56
|
+
|
57
|
+
puts 'flipper get of feature'
|
58
|
+
pp adapter.get(flipper[:stats])
|
59
|
+
# {:boolean=>"true",
|
60
|
+
# :groups=>#<Set: {"admins", "early_access"}>,
|
61
|
+
# :actors=>#<Set: {"180", "25", "90"}>,
|
62
|
+
# :percentage_of_actors=>"45",
|
63
|
+
# :percentage_of_time=>"15"}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/flipper/version', __FILE__)
|
3
|
+
|
4
|
+
flipper_sequel_files = lambda { |file| file =~ /sequel/ }
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.authors = ["John Nunemaker"]
|
8
|
+
gem.email = ["nunemaker@gmail.com"]
|
9
|
+
gem.summary = "Sequel adapter for Flipper"
|
10
|
+
gem.description = "Sequel adapter for Flipper"
|
11
|
+
gem.license = "MIT"
|
12
|
+
gem.homepage = "https://github.com/jnunemaker/flipper"
|
13
|
+
|
14
|
+
extra_files = [
|
15
|
+
"lib/flipper/version.rb",
|
16
|
+
]
|
17
|
+
gem.files = `git ls-files`.split("\n").select(&flipper_sequel_files) + extra_files
|
18
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n").select(&flipper_sequel_files)
|
19
|
+
gem.name = "flipper-sequel"
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
gem.version = Flipper::VERSION
|
22
|
+
|
23
|
+
gem.add_dependency 'flipper', "~> #{Flipper::VERSION}"
|
24
|
+
gem.add_dependency 'sequel', ">= 4.0.0", "< 5"
|
25
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'flipper/adapters/sequel'
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'flipper'
|
3
|
+
require 'sequel'
|
4
|
+
|
5
|
+
module Flipper
|
6
|
+
module Adapters
|
7
|
+
class Sequel
|
8
|
+
include ::Flipper::Adapter
|
9
|
+
|
10
|
+
# Private: Do not use outside of this adapter.
|
11
|
+
class Feature < ::Sequel::Model(:flipper_features)
|
12
|
+
plugin :timestamps, update_on_create: true
|
13
|
+
end
|
14
|
+
|
15
|
+
# Private: Do not use outside of this adapter.
|
16
|
+
class Gate < ::Sequel::Model(:flipper_gates)
|
17
|
+
plugin :timestamps, update_on_create: true
|
18
|
+
end
|
19
|
+
|
20
|
+
# Public: The name of the adapter.
|
21
|
+
attr_reader :name
|
22
|
+
|
23
|
+
# Public: Initialize a new Sequel adapter instance.
|
24
|
+
#
|
25
|
+
# name - The Symbol name for this adapter. Optional (default :active_record)
|
26
|
+
# feature_class - The AR class responsible for the features table.
|
27
|
+
# gate_class - The AR class responsible for the gates table.
|
28
|
+
#
|
29
|
+
# Allowing the overriding of name is so you can differentiate multiple
|
30
|
+
# instances of this adapter from each other, if, for some reason, that is
|
31
|
+
# a thing you do.
|
32
|
+
#
|
33
|
+
# Allowing the overriding of the default feature/gate classes means you
|
34
|
+
# can roll your own tables and what not, if you so desire.
|
35
|
+
def initialize(options = {})
|
36
|
+
@name = options.fetch(:name, :sequel)
|
37
|
+
@feature_class = options.fetch(:feature_class) { Feature }
|
38
|
+
@gate_class = options.fetch(:gate_class) { Gate }
|
39
|
+
end
|
40
|
+
|
41
|
+
# Public: The set of known features.
|
42
|
+
def features
|
43
|
+
@feature_class.all.map(&:key).to_set
|
44
|
+
end
|
45
|
+
|
46
|
+
# Public: Adds a feature to the set of known features.
|
47
|
+
def add(feature)
|
48
|
+
# race condition, but add is only used by enable/disable which happen
|
49
|
+
# super rarely, so it shouldn't matter in practice
|
50
|
+
@feature_class.find_or_create(key: feature.key.to_s)
|
51
|
+
true
|
52
|
+
end
|
53
|
+
|
54
|
+
# Public: Removes a feature from the set of known features.
|
55
|
+
def remove(feature)
|
56
|
+
@feature_class.db.transaction do
|
57
|
+
@feature_class.where(key: feature.key.to_s).delete
|
58
|
+
clear(feature)
|
59
|
+
end
|
60
|
+
true
|
61
|
+
end
|
62
|
+
|
63
|
+
# Public: Clears the gate values for a feature.
|
64
|
+
def clear(feature)
|
65
|
+
@gate_class.where(feature_key: feature.key.to_s).delete
|
66
|
+
true
|
67
|
+
end
|
68
|
+
|
69
|
+
# Public: Gets the values for all gates for a given feature.
|
70
|
+
#
|
71
|
+
# Returns a Hash of Flipper::Gate#key => value.
|
72
|
+
def get(feature)
|
73
|
+
db_gates = @gate_class.where(feature_key: feature.key.to_s).all
|
74
|
+
|
75
|
+
feature.gates.each_with_object({}) do |gate, result|
|
76
|
+
result[gate.key] = case gate.data_type
|
77
|
+
when :boolean
|
78
|
+
if db_gate = db_gates.detect { |db_gate| db_gate.key == gate.key.to_s }
|
79
|
+
db_gate.value
|
80
|
+
end
|
81
|
+
when :integer
|
82
|
+
if db_gate = db_gates.detect { |db_gate| db_gate.key == gate.key.to_s }
|
83
|
+
db_gate.value
|
84
|
+
end
|
85
|
+
when :set
|
86
|
+
db_gates.select { |db_gate| db_gate.key == gate.key.to_s }.map(&:value).to_set
|
87
|
+
else
|
88
|
+
unsupported_data_type gate.data_type
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Public: Enables a gate for a given thing.
|
94
|
+
#
|
95
|
+
# feature - The Flipper::Feature for the gate.
|
96
|
+
# gate - The Flipper::Gate to disable.
|
97
|
+
# thing - The Flipper::Type being disabled for the gate.
|
98
|
+
#
|
99
|
+
# Returns true.
|
100
|
+
def enable(feature, gate, thing)
|
101
|
+
case gate.data_type
|
102
|
+
when :boolean, :integer
|
103
|
+
@gate_class.db.transaction do
|
104
|
+
args = {
|
105
|
+
feature_key: feature.key,
|
106
|
+
key: gate.key.to_s
|
107
|
+
}
|
108
|
+
@gate_class.where(args).delete
|
109
|
+
|
110
|
+
@gate_class.create(gate_attrs(feature, gate, thing))
|
111
|
+
end
|
112
|
+
when :set
|
113
|
+
@gate_class.create(gate_attrs(feature, gate, thing))
|
114
|
+
else
|
115
|
+
unsupported_data_type gate.data_type
|
116
|
+
end
|
117
|
+
|
118
|
+
true
|
119
|
+
end
|
120
|
+
|
121
|
+
# Public: Disables a gate for a given thing.
|
122
|
+
#
|
123
|
+
# feature - The Flipper::Feature for the gate.
|
124
|
+
# gate - The Flipper::Gate to disable.
|
125
|
+
# thing - The Flipper::Type being disabled for the gate.
|
126
|
+
#
|
127
|
+
# Returns true.
|
128
|
+
def disable(feature, gate, thing)
|
129
|
+
case gate.data_type
|
130
|
+
when :boolean
|
131
|
+
clear(feature)
|
132
|
+
when :integer
|
133
|
+
@gate_class.db.transaction do
|
134
|
+
args = {
|
135
|
+
feature_key: feature.key.to_s,
|
136
|
+
key: gate.key.to_s
|
137
|
+
}
|
138
|
+
@gate_class.where(args).delete
|
139
|
+
|
140
|
+
@gate_class.create(gate_attrs(feature, gate, thing))
|
141
|
+
end
|
142
|
+
when :set
|
143
|
+
@gate_class.where(gate_attrs(feature, gate, thing))
|
144
|
+
.delete
|
145
|
+
else
|
146
|
+
unsupported_data_type gate.data_type
|
147
|
+
end
|
148
|
+
|
149
|
+
true
|
150
|
+
end
|
151
|
+
|
152
|
+
private
|
153
|
+
|
154
|
+
def unsupported_data_type(data_type)
|
155
|
+
raise "#{data_type} is not supported by this adapter"
|
156
|
+
end
|
157
|
+
|
158
|
+
def gate_attrs(feature, gate, thing)
|
159
|
+
{
|
160
|
+
feature_key: feature.key.to_s,
|
161
|
+
key: gate.key.to_s,
|
162
|
+
value: thing.value.to_s
|
163
|
+
}
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class CreateFlipperTablesSequel < Sequel::Migration
|
2
|
+
def up
|
3
|
+
create_table :flipper_features do |t|
|
4
|
+
String :key, null: false
|
5
|
+
DateTime :created_at, null: false
|
6
|
+
DateTime :updated_at, null: false
|
7
|
+
end
|
8
|
+
add_index :flipper_features, :key, unique: true
|
9
|
+
|
10
|
+
create_table :flipper_gates do |t|
|
11
|
+
String :feature_key, null: false
|
12
|
+
String :key, null: false
|
13
|
+
String :value
|
14
|
+
DateTime :created_at, null: false
|
15
|
+
DateTime :updated_at, null: false
|
16
|
+
end
|
17
|
+
add_index :flipper_gates, [:feature_key, :key, :value], unique: true
|
18
|
+
end
|
19
|
+
|
20
|
+
def down
|
21
|
+
drop_table :flipper_gates
|
22
|
+
drop_table :flipper_features
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'sequel'
|
3
|
+
|
4
|
+
Sequel::Model.db = Sequel.sqlite(':memory:')
|
5
|
+
Sequel.extension :migration, :core_extensions
|
6
|
+
|
7
|
+
require 'flipper/adapters/sequel'
|
8
|
+
require 'generators/flipper/templates/sequel_migration'
|
9
|
+
require 'flipper/spec/shared_adapter_specs'
|
10
|
+
|
11
|
+
RSpec.describe Flipper::Adapters::Sequel do
|
12
|
+
subject do
|
13
|
+
described_class.new(feature_class: feature_class,
|
14
|
+
gate_class: gate_class)
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:feature_class) { Flipper::Adapters::Sequel::Feature }
|
18
|
+
let(:gate_class) { Flipper::Adapters::Sequel::Gate }
|
19
|
+
|
20
|
+
before(:each) do
|
21
|
+
CreateFlipperTablesSequel.new(Sequel::Model.db).up
|
22
|
+
feature_class.dataset = feature_class.dataset
|
23
|
+
gate_class.dataset = gate_class.dataset
|
24
|
+
end
|
25
|
+
|
26
|
+
after(:each) do
|
27
|
+
CreateFlipperTablesSequel.new(Sequel::Model.db).down
|
28
|
+
end
|
29
|
+
|
30
|
+
it_should_behave_like 'a flipper adapter'
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'sequel'
|
3
|
+
|
4
|
+
Sequel::Model.db = Sequel.sqlite(':memory:')
|
5
|
+
Sequel.extension :migration, :core_extensions
|
6
|
+
|
7
|
+
require 'flipper/adapters/sequel'
|
8
|
+
require 'generators/flipper/templates/sequel_migration'
|
9
|
+
|
10
|
+
class SequelTest < MiniTest::Test
|
11
|
+
prepend Flipper::Test::SharedAdapterTests
|
12
|
+
|
13
|
+
def feature_class
|
14
|
+
Flipper::Adapters::Sequel::Feature
|
15
|
+
end
|
16
|
+
|
17
|
+
def gate_class
|
18
|
+
Flipper::Adapters::Sequel::Gate
|
19
|
+
end
|
20
|
+
|
21
|
+
def setup
|
22
|
+
CreateFlipperTablesSequel.new(Sequel::Model.db).up
|
23
|
+
feature_class.dataset = feature_class.dataset
|
24
|
+
gate_class.dataset = gate_class.dataset
|
25
|
+
@adapter = Flipper::Adapters::Sequel.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def teardown
|
29
|
+
CreateFlipperTablesSequel.new(Sequel::Model.db).down
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flipper-sequel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.10.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Nunemaker
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: flipper
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.10.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.10.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sequel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.0.0
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '5'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 4.0.0
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '5'
|
47
|
+
description: Sequel adapter for Flipper
|
48
|
+
email:
|
49
|
+
- nunemaker@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- docs/sequel/README.md
|
55
|
+
- examples/sequel/basic.rb
|
56
|
+
- examples/sequel/internals.rb
|
57
|
+
- flipper-sequel.gemspec
|
58
|
+
- lib/flipper-sequel.rb
|
59
|
+
- lib/flipper/adapters/sequel.rb
|
60
|
+
- lib/flipper/version.rb
|
61
|
+
- lib/generators/flipper/templates/sequel_migration.rb
|
62
|
+
- spec/flipper/adapters/sequel_spec.rb
|
63
|
+
- test/adapters/sequel_test.rb
|
64
|
+
homepage: https://github.com/jnunemaker/flipper
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.4.5.1
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: Sequel adapter for Flipper
|
88
|
+
test_files:
|
89
|
+
- spec/flipper/adapters/sequel_spec.rb
|
90
|
+
- test/adapters/sequel_test.rb
|