flipper-sequel 1.4.2 → 1.5.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 +4 -4
- data/lib/flipper/adapters/sequel.rb +33 -1
- data/lib/flipper/version.rb +1 -1
- metadata +5 -12
- data/examples/sequel/basic.rb +0 -25
- data/examples/sequel/internals.rb +0 -54
- data/flipper-sequel.gemspec +0 -26
- data/spec/flipper/adapters/sequel_spec.rb +0 -50
- data/spec/flipper/model/sequel_spec.rb +0 -46
- data/spec/support/sequel_setup.rb +0 -5
- data/test/adapters/sequel_test.rb +0 -31
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 92cb7419ccb83c424298e083ad3cbdc685ffb09910642eb54db393e00d802c63
|
|
4
|
+
data.tar.gz: 04e9af2c9d5ac3a2994591e4cebf795ba7afe44a3565772222a332b1747ce04f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e0e28592bad3ffaf673b3b3174f7a6f81a02a63310db50b8ee5e5f03ee2a015f3a41d901af0d1d6a304c61f3887b04bd75103417267afba21177b0cdcfde65c0
|
|
7
|
+
data.tar.gz: 1fa9101e9a0490419778032e5cd9242510057e92088054b26af69c921e69b10c1b442e0559ea3aab8be55985c7e44ff7a22ac91861b426b6c9c18800b36bcaf2
|
|
@@ -54,13 +54,37 @@ module Flipper
|
|
|
54
54
|
warn VALUE_TO_TEXT_WARNING if value_not_text?
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
+
# Private: The sync version lives in the gates table under the reserved
|
|
58
|
+
# feature key SyncVersion::KEY, which has no row in the features table, so
|
|
59
|
+
# features and get_all never see it.
|
|
60
|
+
SYNC_VERSION_GATE_KEY = "sync_version".freeze
|
|
61
|
+
|
|
57
62
|
# Public: The set of known features.
|
|
58
63
|
def features
|
|
59
64
|
@feature_class.all.map(&:key).to_set
|
|
60
65
|
end
|
|
61
66
|
|
|
67
|
+
# Public: The Flipper::SyncVersion of the flags last synced into this
|
|
68
|
+
# adapter, shared by every process using the same tables.
|
|
69
|
+
def sync_version
|
|
70
|
+
SyncVersion.parse(sync_version_dataset.get(:value))
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Public: Records the Flipper::SyncVersion of the flags just synced.
|
|
74
|
+
def sync_version=(version)
|
|
75
|
+
@gate_class.db.transaction do
|
|
76
|
+
sync_version_dataset.delete
|
|
77
|
+
@gate_class.create(
|
|
78
|
+
feature_key: SyncVersion::KEY,
|
|
79
|
+
key: SYNC_VERSION_GATE_KEY,
|
|
80
|
+
value: version.to_s,
|
|
81
|
+
)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
62
85
|
# Public: Adds a feature to the set of known features.
|
|
63
86
|
def add(feature)
|
|
87
|
+
ensure_not_reserved_key!(feature)
|
|
64
88
|
# race condition, but add is only used by enable/disable which happen
|
|
65
89
|
# super rarely, so it shouldn't matter in practice
|
|
66
90
|
@feature_class.find_or_create(key: feature.key.to_s)
|
|
@@ -71,13 +95,15 @@ module Flipper
|
|
|
71
95
|
def remove(feature)
|
|
72
96
|
@feature_class.db.transaction do
|
|
73
97
|
@feature_class.where(key: feature.key.to_s).delete
|
|
74
|
-
|
|
98
|
+
# Removing the reserved name must not delete the sync version.
|
|
99
|
+
clear(feature) unless Flipper.reserved_key?(feature.key)
|
|
75
100
|
end
|
|
76
101
|
true
|
|
77
102
|
end
|
|
78
103
|
|
|
79
104
|
# Public: Clears the gate values for a feature.
|
|
80
105
|
def clear(feature)
|
|
106
|
+
ensure_not_reserved_key!(feature)
|
|
81
107
|
@gate_class.where(feature_key: feature.key.to_s).delete
|
|
82
108
|
true
|
|
83
109
|
end
|
|
@@ -129,6 +155,7 @@ module Flipper
|
|
|
129
155
|
#
|
|
130
156
|
# Returns true.
|
|
131
157
|
def enable(feature, gate, thing)
|
|
158
|
+
ensure_not_reserved_key!(feature)
|
|
132
159
|
case gate.data_type
|
|
133
160
|
when :boolean
|
|
134
161
|
set(feature, gate, thing, clear: true)
|
|
@@ -153,6 +180,7 @@ module Flipper
|
|
|
153
180
|
#
|
|
154
181
|
# Returns true.
|
|
155
182
|
def disable(feature, gate, thing)
|
|
183
|
+
ensure_not_reserved_key!(feature)
|
|
156
184
|
case gate.data_type
|
|
157
185
|
when :boolean
|
|
158
186
|
clear(feature)
|
|
@@ -175,6 +203,10 @@ module Flipper
|
|
|
175
203
|
raise "#{data_type} is not supported by this adapter"
|
|
176
204
|
end
|
|
177
205
|
|
|
206
|
+
def sync_version_dataset
|
|
207
|
+
@gate_class.where(feature_key: SyncVersion::KEY, key: SYNC_VERSION_GATE_KEY)
|
|
208
|
+
end
|
|
209
|
+
|
|
178
210
|
def set(feature, gate, thing, options = {})
|
|
179
211
|
clear_feature = options.fetch(:clear, false)
|
|
180
212
|
json_feature = options.fetch(:json, false)
|
data/lib/flipper/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: flipper-sequel
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.5.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: 2026-
|
|
11
|
+
date: 2026-11-24 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: 1.
|
|
19
|
+
version: 1.5.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: 1.
|
|
26
|
+
version: 1.5.0.rc1
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: sequel
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -50,18 +50,11 @@ executables: []
|
|
|
50
50
|
extensions: []
|
|
51
51
|
extra_rdoc_files: []
|
|
52
52
|
files:
|
|
53
|
-
- examples/sequel/basic.rb
|
|
54
|
-
- examples/sequel/internals.rb
|
|
55
|
-
- flipper-sequel.gemspec
|
|
56
53
|
- lib/flipper-sequel.rb
|
|
57
54
|
- lib/flipper/adapters/sequel.rb
|
|
58
55
|
- lib/flipper/model/sequel.rb
|
|
59
56
|
- lib/flipper/version.rb
|
|
60
57
|
- lib/generators/flipper/templates/sequel_migration.rb
|
|
61
|
-
- spec/flipper/adapters/sequel_spec.rb
|
|
62
|
-
- spec/flipper/model/sequel_spec.rb
|
|
63
|
-
- spec/support/sequel_setup.rb
|
|
64
|
-
- test/adapters/sequel_test.rb
|
|
65
58
|
homepage: https://www.flippercloud.io/docs/adapters/sequel
|
|
66
59
|
licenses:
|
|
67
60
|
- MIT
|
|
@@ -70,7 +63,7 @@ metadata:
|
|
|
70
63
|
homepage_uri: https://www.flippercloud.io
|
|
71
64
|
source_code_uri: https://github.com/flippercloud/flipper
|
|
72
65
|
bug_tracker_uri: https://github.com/flippercloud/flipper/issues
|
|
73
|
-
changelog_uri: https://github.com/flippercloud/flipper/releases/tag/v1.
|
|
66
|
+
changelog_uri: https://github.com/flippercloud/flipper/releases/tag/v1.5.0.rc1
|
|
74
67
|
funding_uri: https://github.com/sponsors/flippercloud
|
|
75
68
|
post_install_message:
|
|
76
69
|
rdoc_options: []
|
data/examples/sequel/basic.rb
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
require 'bundler/setup'
|
|
2
|
-
require 'sequel'
|
|
3
|
-
Sequel::Model.db = Sequel.sqlite(':memory:')
|
|
4
|
-
Sequel.extension :migration, :core_extensions
|
|
5
|
-
|
|
6
|
-
require 'generators/flipper/templates/sequel_migration'
|
|
7
|
-
CreateFlipperTablesSequel.new(Sequel::Model.db).up
|
|
8
|
-
|
|
9
|
-
require 'flipper/adapters/sequel'
|
|
10
|
-
|
|
11
|
-
Flipper[:stats].enable
|
|
12
|
-
|
|
13
|
-
if Flipper[:stats].enabled?
|
|
14
|
-
puts "Enabled!"
|
|
15
|
-
else
|
|
16
|
-
puts "Disabled!"
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
Flipper[:stats].disable
|
|
20
|
-
|
|
21
|
-
if Flipper[:stats].enabled?
|
|
22
|
-
puts "Enabled!"
|
|
23
|
-
else
|
|
24
|
-
puts "Disabled!"
|
|
25
|
-
end
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
require 'bundler/setup'
|
|
2
|
-
require 'sequel'
|
|
3
|
-
Sequel::Model.db = Sequel.sqlite(':memory:')
|
|
4
|
-
Sequel.extension :migration, :core_extensions
|
|
5
|
-
|
|
6
|
-
require 'generators/flipper/templates/sequel_migration'
|
|
7
|
-
CreateFlipperTablesSequel.new(Sequel::Model.db).up
|
|
8
|
-
|
|
9
|
-
require 'flipper/adapters/sequel'
|
|
10
|
-
|
|
11
|
-
# Register a few groups.
|
|
12
|
-
Flipper.register(:admins) { |actor| actor.admin? }
|
|
13
|
-
Flipper.register(:early_access) { |actor| actor.early_access? }
|
|
14
|
-
|
|
15
|
-
# Create a user class that has flipper_id instance method.
|
|
16
|
-
User = Struct.new(:flipper_id)
|
|
17
|
-
|
|
18
|
-
Flipper[:stats].enable
|
|
19
|
-
Flipper[:stats].enable_group :admins
|
|
20
|
-
Flipper[:stats].enable_group :early_access
|
|
21
|
-
Flipper[:stats].enable_actor User.new('25')
|
|
22
|
-
Flipper[:stats].enable_actor User.new('90')
|
|
23
|
-
Flipper[:stats].enable_actor User.new('180')
|
|
24
|
-
Flipper[:stats].enable_percentage_of_time 15
|
|
25
|
-
Flipper[:stats].enable_percentage_of_actors 45
|
|
26
|
-
|
|
27
|
-
Flipper[:search].enable
|
|
28
|
-
|
|
29
|
-
puts 'all rows in features table'
|
|
30
|
-
pp Flipper::Adapters::Sequel::Feature.all
|
|
31
|
-
#[#<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}>,
|
|
32
|
-
# #<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}>]
|
|
33
|
-
puts
|
|
34
|
-
|
|
35
|
-
puts 'all rows in gates table'
|
|
36
|
-
pp Flipper::Adapters::Sequel::Gate.all
|
|
37
|
-
# [#<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}>,
|
|
38
|
-
# #<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}>,
|
|
39
|
-
# #<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}>,
|
|
40
|
-
# #<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}>,
|
|
41
|
-
# #<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}>,
|
|
42
|
-
# #<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}>,
|
|
43
|
-
# #<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}>,
|
|
44
|
-
# #<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}>,
|
|
45
|
-
# #<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}>]
|
|
46
|
-
puts
|
|
47
|
-
|
|
48
|
-
puts 'flipper get of feature'
|
|
49
|
-
pp Flipper.adapter.get(Flipper[:stats])
|
|
50
|
-
# {:boolean=>"true",
|
|
51
|
-
# :groups=>#<Set: {"admins", "early_access"}>,
|
|
52
|
-
# :actors=>#<Set: {"180", "25", "90"}>,
|
|
53
|
-
# :percentage_of_actors=>"45",
|
|
54
|
-
# :percentage_of_time=>"15"}
|
data/flipper-sequel.gemspec
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
|
2
|
-
require File.expand_path('../lib/flipper/version', __FILE__)
|
|
3
|
-
require File.expand_path('../lib/flipper/metadata', __FILE__)
|
|
4
|
-
|
|
5
|
-
flipper_sequel_files = ->(file) { file =~ /sequel/ }
|
|
6
|
-
|
|
7
|
-
Gem::Specification.new do |gem|
|
|
8
|
-
gem.authors = ['John Nunemaker']
|
|
9
|
-
gem.email = 'support@flippercloud.io'
|
|
10
|
-
gem.summary = 'Sequel feature flag adapter for Flipper'
|
|
11
|
-
gem.license = 'MIT'
|
|
12
|
-
gem.homepage = 'https://www.flippercloud.io/docs/adapters/sequel'
|
|
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
|
-
gem.metadata = Flipper::METADATA
|
|
23
|
-
|
|
24
|
-
gem.add_dependency 'flipper', "~> #{Flipper::VERSION}"
|
|
25
|
-
gem.add_dependency 'sequel', '>= 4.0.0', '< 6'
|
|
26
|
-
end
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
require 'sequel'
|
|
2
|
-
|
|
3
|
-
Sequel::Model.db = Sequel.sqlite(':memory:')
|
|
4
|
-
Sequel.extension :migration, :core_extensions
|
|
5
|
-
|
|
6
|
-
require 'flipper/adapters/sequel'
|
|
7
|
-
require 'generators/flipper/templates/sequel_migration'
|
|
8
|
-
|
|
9
|
-
RSpec.describe Flipper::Adapters::Sequel do
|
|
10
|
-
subject do
|
|
11
|
-
described_class.new(feature_class: feature_class,
|
|
12
|
-
gate_class: gate_class)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
let(:feature_class) { Flipper::Adapters::Sequel::Feature }
|
|
16
|
-
let(:gate_class) { Flipper::Adapters::Sequel::Gate }
|
|
17
|
-
|
|
18
|
-
before(:each) do
|
|
19
|
-
CreateFlipperTablesSequel.new(Sequel::Model.db).up
|
|
20
|
-
feature_class.dataset = feature_class.dataset
|
|
21
|
-
gate_class.dataset = gate_class.dataset
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
after(:each) do
|
|
25
|
-
CreateFlipperTablesSequel.new(Sequel::Model.db).down
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it_should_behave_like 'a flipper adapter'
|
|
29
|
-
|
|
30
|
-
context 'requiring "flipper-sequel"' do
|
|
31
|
-
before do
|
|
32
|
-
Flipper.configuration = nil
|
|
33
|
-
Flipper.instance = nil
|
|
34
|
-
|
|
35
|
-
silence { load 'flipper/adapters/sequel.rb' }
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it 'configures itself' do
|
|
39
|
-
expect(Flipper.adapter.adapter).to be_a(Flipper::Adapters::Sequel)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "defines #flipper_id on Sequel::Model" do
|
|
43
|
-
expect(Sequel::Model.ancestors).to include(Flipper::Identifier)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "defines #flipper_properties on Sequel::Model" do
|
|
47
|
-
expect(Sequel::Model.ancestors).to include(Flipper::Model::Sequel)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
require 'flipper/model/sequel'
|
|
2
|
-
|
|
3
|
-
RSpec.describe Flipper::Model::Sequel do
|
|
4
|
-
before(:each) do
|
|
5
|
-
Sequel::Model.db.run <<-SQL
|
|
6
|
-
CREATE TABLE users (
|
|
7
|
-
id integer PRIMARY KEY,
|
|
8
|
-
name string NOT NULL,
|
|
9
|
-
age integer,
|
|
10
|
-
is_confirmed boolean,
|
|
11
|
-
created_at datetime NOT NULL,
|
|
12
|
-
updated_at datetime NOT NULL
|
|
13
|
-
)
|
|
14
|
-
SQL
|
|
15
|
-
|
|
16
|
-
@User = Class.new(::Sequel::Model(:users)) do
|
|
17
|
-
include Flipper::Model::Sequel
|
|
18
|
-
plugin :timestamps, update_on_create: true
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def self.name
|
|
22
|
-
'User'
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
after(:each) do
|
|
28
|
-
Sequel::Model.db.run("DROP table IF EXISTS `users`")
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
describe "flipper_properties" do
|
|
32
|
-
subject { @User.create(name: "Test", age: 22, is_confirmed: true) }
|
|
33
|
-
|
|
34
|
-
it "includes all attributes" do
|
|
35
|
-
expect(subject.flipper_properties).to eq({
|
|
36
|
-
"type" => "User",
|
|
37
|
-
"id" => subject.id,
|
|
38
|
-
"name" => "Test",
|
|
39
|
-
"age" => 22,
|
|
40
|
-
"is_confirmed" => true,
|
|
41
|
-
"created_at" => subject.created_at,
|
|
42
|
-
"updated_at" => subject.updated_at
|
|
43
|
-
})
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|