flipper-active_record 0.22.0 → 0.23.1
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86652e532be8297da0822f29d72d70360366aec4f3a5371132abc3ed5d16b438
|
4
|
+
data.tar.gz: 2352975ae77bc5a0bfda848100d373ecbfe1711728df0ddf06e54b183090c971
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 988f22fd08707d8bcb9131cdedb98af4db3f7d1254198f5bce196433d0adc8c27cf338494e371f0f5cbabacb4080d128a7d6ec94a1ae6c170ffbbb5a08ceddee
|
7
|
+
data.tar.gz: 1a9228d0d6a0c9cbf123adaed45c839ee8815fa50eff9bfd7746b2d0bce5bf9902c6a1f5e112412355f99f4f320b0c17426985fb51a5e06aa2b21fbd5f55d4c5
|
@@ -173,10 +173,15 @@ module Flipper
|
|
173
173
|
@gate_class.transaction do
|
174
174
|
clear(feature) if clear_feature
|
175
175
|
@gate_class.where(feature_key: feature.key, key: gate.key).destroy_all
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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
|
180
185
|
end
|
181
186
|
end
|
182
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.1
|
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: 2022-01-19 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.23.1
|
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.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
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
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
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
|