flipper-active_record 0.21.0 → 0.23.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 +4 -4
- data/flipper-active_record.gemspec +1 -1
- data/lib/flipper/adapters/active_record.rb +15 -9
- data/lib/flipper/version.rb +1 -1
- data/spec/flipper/adapters/active_record_spec.rb +0 -2
- metadata +9 -10
- data/docs/active_record/README.md +0 -156
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e230d47ea0260497feb15587a8d67b2820a3f43845aca3f07137c0d9003413a
|
4
|
+
data.tar.gz: 682c323dfc39cf85f11ef7ebf2887d2d44ba0abc904194cf88f319c7d9ce65b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed98478b3622f3af55513f0597f8e3e4d932e274ea53d9ac4e5202aaa86743f37246ce933beda9739feeb77254a6dd547b8c4b21cfc1e6bb9d7a295def3132c8
|
7
|
+
data.tar.gz: cd915699d669fb083a4603086b96698f08681e6fdab1ba378afb440c267b819c6040ff400d1ffded79e5d4d8637af0ac3e106729e4ad040b6f53be31e4b5ba1d
|
@@ -101,11 +101,12 @@ module Flipper
|
|
101
101
|
end
|
102
102
|
|
103
103
|
def get_all
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
104
|
+
features = ::Arel::Table.new(@feature_class.table_name.to_sym)
|
105
|
+
gates = ::Arel::Table.new(@gate_class.table_name.to_sym)
|
106
|
+
rows_query = features.join(gates, Arel::Nodes::OuterJoin)
|
107
|
+
.on(features[:key].eq(gates[:feature_key]))
|
108
|
+
.project(features[:key].as('feature_key'), gates[:key], gates[:value])
|
109
|
+
rows = ::ActiveRecord::Base.connection.select_all rows_query
|
109
110
|
db_gates = rows.map { |row| Gate.new(row) }
|
110
111
|
grouped_db_gates = db_gates.group_by(&:feature_key)
|
111
112
|
result = Hash.new { |hash, key| hash[key] = default_config }
|
@@ -172,10 +173,15 @@ module Flipper
|
|
172
173
|
@gate_class.transaction do
|
173
174
|
clear(feature) if clear_feature
|
174
175
|
@gate_class.where(feature_key: feature.key, key: gate.key).destroy_all
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
176
|
+
begin
|
177
|
+
@gate_class.create! do |g|
|
178
|
+
g.feature_key = feature.key
|
179
|
+
g.key = gate.key
|
180
|
+
g.value = thing.value.to_s
|
181
|
+
end
|
182
|
+
rescue ::ActiveRecord::RecordNotUnique
|
183
|
+
# assume this happened concurrently with the same thing and its fine
|
184
|
+
# see https://github.com/jnunemaker/flipper/issues/544
|
179
185
|
end
|
180
186
|
end
|
181
187
|
|
data/lib/flipper/version.rb
CHANGED
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.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-
|
11
|
+
date: 2021-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: flipper
|
@@ -16,34 +16,34 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 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.
|
26
|
+
version: 0.23.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '4.2'
|
34
34
|
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: '
|
36
|
+
version: '8'
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
43
|
+
version: '4.2'
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
46
|
+
version: '8'
|
47
47
|
description:
|
48
48
|
email:
|
49
49
|
- nunemaker@gmail.com
|
@@ -51,7 +51,6 @@ executables: []
|
|
51
51
|
extensions: []
|
52
52
|
extra_rdoc_files: []
|
53
53
|
files:
|
54
|
-
- docs/active_record/README.md
|
55
54
|
- examples/active_record/ar_setup.rb
|
56
55
|
- examples/active_record/basic.rb
|
57
56
|
- examples/active_record/internals.rb
|
@@ -84,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
83
|
- !ruby/object:Gem::Version
|
85
84
|
version: '0'
|
86
85
|
requirements: []
|
87
|
-
rubygems_version: 3.
|
86
|
+
rubygems_version: 3.1.2
|
88
87
|
signing_key:
|
89
88
|
specification_version: 4
|
90
89
|
summary: ActiveRecord adapter for Flipper
|
@@ -1,156 +0,0 @@
|
|
1
|
-
# Flipper ActiveRecord
|
2
|
-
|
3
|
-
An ActiveRecord adapter for [Flipper](https://github.com/jnunemaker/flipper).
|
4
|
-
|
5
|
-
Supported Active Record versions:
|
6
|
-
|
7
|
-
* 5.0.x
|
8
|
-
* 6.0.x
|
9
|
-
|
10
|
-
## Installation
|
11
|
-
|
12
|
-
Add this line to your application's Gemfile:
|
13
|
-
|
14
|
-
gem 'flipper-active_record'
|
15
|
-
|
16
|
-
And then execute:
|
17
|
-
|
18
|
-
$ bundle
|
19
|
-
|
20
|
-
Or install it yourself with:
|
21
|
-
|
22
|
-
$ gem install flipper-active_record
|
23
|
-
|
24
|
-
## Usage
|
25
|
-
|
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
|
-
|
28
|
-
$ rails g flipper:active_record
|
29
|
-
|
30
|
-
Note that the active record adapter requires the database tables to be created in order to work; failure to run the migration first will cause an exception to be raised when attempting to initialize the active record adapter.
|
31
|
-
|
32
|
-
Flipper will be configured to use the ActiveRecord adapter when `flipper-active_record` is loaded. But **if you need to customize the adapter**, you can add this to an initializer:
|
33
|
-
|
34
|
-
```ruby
|
35
|
-
require 'flipper/adapters/active_record'
|
36
|
-
Flipper.configure do |config|
|
37
|
-
config.adapter { Flipper::Adapters::ActiveRecord.new }
|
38
|
-
end
|
39
|
-
```
|
40
|
-
|
41
|
-
## Internals
|
42
|
-
|
43
|
-
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.
|
44
|
-
|
45
|
-
```ruby
|
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.enable :stats
|
54
|
-
Flipper.enable_group :stats, :admins
|
55
|
-
Flipper.enable_group :stats, :early_access
|
56
|
-
Flipper.enable_actor :stats, User.new('25')
|
57
|
-
Flipper.enable_actor :stats, User.new('90')
|
58
|
-
Flipper.enable_actor :stats, User.new('180')
|
59
|
-
Flipper.enable_percentage_of_time :stats, 15
|
60
|
-
Flipper.enable_percentage_of_actors :stats, 45
|
61
|
-
|
62
|
-
Flipper.enable :search
|
63
|
-
|
64
|
-
puts 'all rows in features table'
|
65
|
-
pp Flipper::Adapters::ActiveRecord::Feature.all
|
66
|
-
# [#<Flipper::Adapters::ActiveRecord::Feature:0x007fd259b47110
|
67
|
-
# id: 1,
|
68
|
-
# key: "stats",
|
69
|
-
# created_at: 2015-12-21 16:26:29 UTC,
|
70
|
-
# updated_at: 2015-12-21 16:26:29 UTC>,
|
71
|
-
# #<Flipper::Adapters::ActiveRecord::Feature:0x007fd259b46cd8
|
72
|
-
# id: 2,
|
73
|
-
# key: "search",
|
74
|
-
# created_at: 2015-12-21 16:26:29 UTC,
|
75
|
-
# updated_at: 2015-12-21 16:26:29 UTC>]
|
76
|
-
puts
|
77
|
-
|
78
|
-
puts 'all rows in gates table'
|
79
|
-
pp Flipper::Adapters::ActiveRecord::Gate.all
|
80
|
-
# [#<Flipper::Adapters::ActiveRecord::Gate:0x007fd259b0f0f8
|
81
|
-
# id: 1,
|
82
|
-
# feature_key: "stats",
|
83
|
-
# key: "boolean",
|
84
|
-
# value: "true",
|
85
|
-
# created_at: 2015-12-21 16:26:29 UTC,
|
86
|
-
# updated_at: 2015-12-21 16:26:29 UTC>,
|
87
|
-
# #<Flipper::Adapters::ActiveRecord::Gate:0x007fd259b0ebd0
|
88
|
-
# id: 2,
|
89
|
-
# feature_key: "stats",
|
90
|
-
# key: "groups",
|
91
|
-
# value: "admins",
|
92
|
-
# created_at: 2015-12-21 16:26:29 UTC,
|
93
|
-
# updated_at: 2015-12-21 16:26:29 UTC>,
|
94
|
-
# #<Flipper::Adapters::ActiveRecord::Gate:0x007fd259b0e748
|
95
|
-
# id: 3,
|
96
|
-
# feature_key: "stats",
|
97
|
-
# key: "groups",
|
98
|
-
# value: "early_access",
|
99
|
-
# created_at: 2015-12-21 16:26:29 UTC,
|
100
|
-
# updated_at: 2015-12-21 16:26:29 UTC>,
|
101
|
-
# #<Flipper::Adapters::ActiveRecord::Gate:0x007fd259b0e568
|
102
|
-
# id: 4,
|
103
|
-
# feature_key: "stats",
|
104
|
-
# key: "actors",
|
105
|
-
# value: "25",
|
106
|
-
# created_at: 2015-12-21 16:26:29 UTC,
|
107
|
-
# updated_at: 2015-12-21 16:26:29 UTC>,
|
108
|
-
# #<Flipper::Adapters::ActiveRecord::Gate:0x007fd259b0e0b8
|
109
|
-
# id: 5,
|
110
|
-
# feature_key: "stats",
|
111
|
-
# key: "actors",
|
112
|
-
# value: "90",
|
113
|
-
# created_at: 2015-12-21 16:26:29 UTC,
|
114
|
-
# updated_at: 2015-12-21 16:26:29 UTC>,
|
115
|
-
# #<Flipper::Adapters::ActiveRecord::Gate:0x007fd259b0da50
|
116
|
-
# id: 6,
|
117
|
-
# feature_key: "stats",
|
118
|
-
# key: "actors",
|
119
|
-
# value: "180",
|
120
|
-
# created_at: 2015-12-21 16:26:29 UTC,
|
121
|
-
# updated_at: 2015-12-21 16:26:29 UTC>,
|
122
|
-
# #<Flipper::Adapters::ActiveRecord::Gate:0x007fd259b0d3c0
|
123
|
-
# id: 7,
|
124
|
-
# feature_key: "stats",
|
125
|
-
# key: "percentage_of_time",
|
126
|
-
# value: "15",
|
127
|
-
# created_at: 2015-12-21 16:26:29 UTC,
|
128
|
-
# updated_at: 2015-12-21 16:26:29 UTC>,
|
129
|
-
# #<Flipper::Adapters::ActiveRecord::Gate:0x007fd259b0cdf8
|
130
|
-
# id: 8,
|
131
|
-
# feature_key: "stats",
|
132
|
-
# key: "percentage_of_actors",
|
133
|
-
# value: "45",
|
134
|
-
# created_at: 2015-12-21 16:26:29 UTC,
|
135
|
-
# updated_at: 2015-12-21 16:26:29 UTC>,
|
136
|
-
# #<Flipper::Adapters::ActiveRecord::Gate:0x007fd259b0cbf0
|
137
|
-
# id: 9,
|
138
|
-
# feature_key: "search",
|
139
|
-
# key: "boolean",
|
140
|
-
# value: "true",
|
141
|
-
# created_at: 2015-12-21 16:26:29 UTC,
|
142
|
-
# updated_at: 2015-12-21 16:26:29 UTC>]
|
143
|
-
puts
|
144
|
-
|
145
|
-
puts 'flipper get of feature'
|
146
|
-
pp adapter.get(flipper[:stats])
|
147
|
-
# flipper get of feature
|
148
|
-
```
|
149
|
-
|
150
|
-
## Contributing
|
151
|
-
|
152
|
-
1. Fork it
|
153
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
154
|
-
3. Commit your changes (`git commit -am 'Added some feature'`)
|
155
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
156
|
-
5. Create new Pull Request
|