flipper-sequel 0.21.0 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa83337636b5039464206b454335756a1065343c1ae8d7fe8083b4d27dcf604e
4
- data.tar.gz: 32af671861afdf85d3a6c800fa38e6223cef9fa67fc837db1b19a03b1d206857
3
+ metadata.gz: e8e3f9947bf861064bf8986d7456aebd581a448d907fdcaff54c02c92ca2197f
4
+ data.tar.gz: a53796f762aaa927baafdfae6dfae234c5f27510069ea980ab64ee09430ac650
5
5
  SHA512:
6
- metadata.gz: a613b22e95c6c5478837cece0f58508d5e92b51e3b9902a873146b17813ffbd3fdd9dccd89ec8bd4bd8fe0b36a3e4743c9947b28244c54d3c549d4f620f7ef88
7
- data.tar.gz: 5d5eef8a95a52645e07ef5d10c201dc32d9551941168f53df10ff7c847a5c6b327f3739ab6c1eee8ee98dd56cbe994232711775feb99693b3e405313835a4d10
6
+ metadata.gz: 571d14ed54c82b7b6e6da8afb61a15fe9345ac4d7341d2f40a5036e2989caaff1ea9182cf19bf930c6815f41839af5f6909a4318dc8dce6cb963e4e5b2036578
7
+ data.tar.gz: 50447c3d780a7794cd3d0cb1469b99532517983657f071b809d4bf4d219b152bde2c622baeb5187dea6233a17e04c87cc8a1639504dd29284bd19ad862fef2a8
@@ -97,11 +97,15 @@ module Flipper
97
97
  end
98
98
 
99
99
  def get_all
100
- db_gates = @gate_class.fetch(<<-SQL).to_a
101
- SELECT ff.key AS feature_key, fg.key, fg.value
102
- FROM #{@feature_class.table_name} ff
103
- LEFT JOIN #{@gate_class.table_name} fg ON ff.key = fg.feature_key
104
- SQL
100
+ feature_table = @feature_class.table_name.to_sym
101
+ gate_table = @gate_class.table_name.to_sym
102
+ features_sql = @feature_class.select(:key.qualify(feature_table).as(:feature_key))
103
+ .select_append(:key.qualify(gate_table))
104
+ .select_append(:value.qualify(gate_table))
105
+ .left_join(@gate_class.table_name.to_sym, feature_key: :key)
106
+ .sql
107
+
108
+ db_gates = @gate_class.fetch(features_sql).to_a
105
109
  grouped_db_gates = db_gates.group_by(&:feature_key)
106
110
  result = Hash.new { |hash, key| hash[key] = default_config }
107
111
  features = grouped_db_gates.keys.map { |key| Flipper::Feature.new(key, self) }
@@ -175,7 +179,11 @@ module Flipper
175
179
  @gate_class.db.transaction do
176
180
  clear(feature) if clear_feature
177
181
  @gate_class.where(args).delete
178
- @gate_class.create(gate_attrs(feature, gate, thing))
182
+
183
+ begin
184
+ @gate_class.create(gate_attrs(feature, gate, thing))
185
+ rescue ::Sequel::UniqueConstraintViolation
186
+ end
179
187
  end
180
188
  end
181
189
 
@@ -1,3 +1,3 @@
1
1
  module Flipper
2
- VERSION = '0.21.0'.freeze
2
+ VERSION = '0.23.0'.freeze
3
3
  end
@@ -1,4 +1,3 @@
1
- require 'helper'
2
1
  require 'sequel'
3
2
 
4
3
  Sequel::Model.db = Sequel.sqlite(':memory:')
@@ -6,7 +5,6 @@ Sequel.extension :migration, :core_extensions
6
5
 
7
6
  require 'flipper/adapters/sequel'
8
7
  require 'generators/flipper/templates/sequel_migration'
9
- require 'flipper/spec/shared_adapter_specs'
10
8
 
11
9
  RSpec.describe Flipper::Adapters::Sequel do
12
10
  subject do
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: 0.21.0
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-09 00:00:00.000000000 Z
11
+ date: 2021-12-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: 0.21.0
19
+ version: 0.23.0
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.21.0
26
+ version: 0.23.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sequel
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -51,7 +51,6 @@ executables: []
51
51
  extensions: []
52
52
  extra_rdoc_files: []
53
53
  files:
54
- - docs/sequel/README.md
55
54
  - examples/sequel/basic.rb
56
55
  - examples/sequel/internals.rb
57
56
  - flipper-sequel.gemspec
@@ -81,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
80
  - !ruby/object:Gem::Version
82
81
  version: '0'
83
82
  requirements: []
84
- rubygems_version: 3.0.3
83
+ rubygems_version: 3.1.2
85
84
  signing_key:
86
85
  specification_version: 4
87
86
  summary: Sequel adapter for Flipper
@@ -1,103 +0,0 @@
1
- # Flipper Sequel
2
-
3
- A [Sequel](https://github.com/jeremyevans/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 by simply requiring it:
29
-
30
- ```ruby
31
- require 'flipper-sequel`
32
- ```
33
-
34
- **If you need to customize the adapter**, you can add this to an initializer:
35
-
36
- ```ruby
37
- Flipper.configure do |config|
38
- config.adapter { Flipper::Adapters::Sequel.new }
39
- end
40
- ```
41
-
42
- ## Internals
43
-
44
- 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.
45
-
46
- ```ruby
47
- require 'flipper/adapters/sequel'
48
- adapter = Flipper::Adapters::Sequel.new
49
- flipper = Flipper.new(adapter)
50
-
51
- # Register a few groups.
52
- Flipper.register(:admins) { |thing| thing.admin? }
53
- Flipper.register(:early_access) { |thing| thing.early_access? }
54
-
55
- # Create a user class that has flipper_id instance method.
56
- User = Struct.new(:flipper_id)
57
-
58
- flipper[:stats].enable
59
- flipper[:stats].enable_group :admins
60
- flipper[:stats].enable_group :early_access
61
- flipper[:stats].enable_actor User.new('25')
62
- flipper[:stats].enable_actor User.new('90')
63
- flipper[:stats].enable_actor User.new('180')
64
- flipper[:stats].enable_percentage_of_time 15
65
- flipper[:stats].enable_percentage_of_actors 45
66
-
67
- flipper[:search].enable
68
-
69
- puts 'all rows in features table'
70
- pp Flipper::Adapters::Sequel::Feature.all
71
- #[#<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}>,
72
- # #<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}>]
73
- puts
74
-
75
- puts 'all rows in gates table'
76
- pp Flipper::Adapters::Sequel::Gate.all
77
- # [#<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}>,
78
- # #<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}>,
79
- # #<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}>,
80
- # #<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}>,
81
- # #<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}>,
82
- # #<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}>,
83
- # #<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}>,
84
- # #<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}>,
85
- # #<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}>]
86
- puts
87
-
88
- puts 'flipper get of feature'
89
- pp adapter.get(flipper[:stats])
90
- # {:boolean=>"true",
91
- # :groups=>#<Set: {"admins", "early_access"}>,
92
- # :actors=>#<Set: {"180", "25", "90"}>,
93
- # :percentage_of_actors=>"45",
94
- # :percentage_of_time=>"15"}
95
- ```
96
-
97
- ## Contributing
98
-
99
- 1. Fork it
100
- 2. Create your feature branch (`git checkout -b my-new-feature`)
101
- 3. Commit your changes (`git commit -am 'Added some feature'`)
102
- 4. Push to the branch (`git push origin my-new-feature`)
103
- 5. Create new Pull Request