flipper-activerecord3dot2 0.1.1 → 0.1.2
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/.gitignore +34 -0
- data/.travis.yml +5 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +105 -0
- data/Guardfile +13 -0
- data/LICENSE +22 -0
- data/README.md +176 -0
- data/Rakefile +4 -0
- data/flipper-activerecord3dot2.gemspec +17 -0
- data/lib/flipper-activerecord.rb +1 -0
- data/lib/flipper/activerecord/feature.rb +9 -0
- data/lib/flipper/activerecord/gate.rb +9 -0
- data/lib/flipper/adapters/activerecord.rb +149 -0
- data/lib/flipper/adapters/activerecord/version.rb +7 -0
- data/lib/generators/flipper/active_record_generator.rb +21 -0
- data/lib/generators/flipper/templates/migration.rb +28 -0
- data/script/release +42 -0
- data/spec/activerecord_spec.rb +9 -0
- data/spec/database.yml +4 -0
- data/spec/helper.rb +56 -0
- metadata +48 -23
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 9684c3c1468c48b55bcead8688d670787762e605
|
|
4
|
+
data.tar.gz: 3d79c5d805ae65d93868e1b6069ae281338f51c6
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 400168ca896e02b9d7878de704e6c2d8f6b1dda0b1f83d7162ee94769ec3efb4a6283c231729ea64e3b65599e871ca85910654725fc08eda952d6528fdab7f78
|
|
7
|
+
data.tar.gz: d65f7cbbd1f86adb6bff205f9c25a6ed163acdc4f1f6ecdf8b5d4868335a172cc35c9c4bfbfebaa03c33a849dc5ff12c7145ba62338d84b79a62c4e9f5597760
|
data/.gitignore
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
/.config
|
|
4
|
+
/coverage/
|
|
5
|
+
/InstalledFiles
|
|
6
|
+
/pkg/
|
|
7
|
+
/spec/reports/
|
|
8
|
+
/test/tmp/
|
|
9
|
+
/test/version_tmp/
|
|
10
|
+
/tmp/
|
|
11
|
+
|
|
12
|
+
## Specific to RubyMotion:
|
|
13
|
+
.dat*
|
|
14
|
+
.repl_history
|
|
15
|
+
build/
|
|
16
|
+
|
|
17
|
+
## Documentation cache and generated files:
|
|
18
|
+
/.yardoc/
|
|
19
|
+
/_yardoc/
|
|
20
|
+
/doc/
|
|
21
|
+
/rdoc/
|
|
22
|
+
|
|
23
|
+
## Environment normalisation:
|
|
24
|
+
/.bundle/
|
|
25
|
+
/lib/bundler/man/
|
|
26
|
+
|
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
29
|
+
# Gemfile.lock
|
|
30
|
+
# .ruby-version
|
|
31
|
+
# .ruby-gemset
|
|
32
|
+
|
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
34
|
+
.rvmrc
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
flipper-activerecord3dot2 (0.1.1)
|
|
5
|
+
activerecord (>= 3.2.21, < 4.2)
|
|
6
|
+
flipper (~> 0.6)
|
|
7
|
+
foreigner (~> 1.7, >= 1.7.4)
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: https://rubygems.org/
|
|
11
|
+
specs:
|
|
12
|
+
activemodel (4.1.13)
|
|
13
|
+
activesupport (= 4.1.13)
|
|
14
|
+
builder (~> 3.1)
|
|
15
|
+
activerecord (4.1.13)
|
|
16
|
+
activemodel (= 4.1.13)
|
|
17
|
+
activesupport (= 4.1.13)
|
|
18
|
+
arel (~> 5.0.0)
|
|
19
|
+
activesupport (4.1.13)
|
|
20
|
+
i18n (~> 0.6, >= 0.6.9)
|
|
21
|
+
json (~> 1.7, >= 1.7.7)
|
|
22
|
+
minitest (~> 5.1)
|
|
23
|
+
thread_safe (~> 0.1)
|
|
24
|
+
tzinfo (~> 1.1)
|
|
25
|
+
arel (5.0.1.20140414130214)
|
|
26
|
+
builder (3.2.2)
|
|
27
|
+
celluloid (0.16.0)
|
|
28
|
+
timers (~> 4.0.0)
|
|
29
|
+
coderay (1.1.0)
|
|
30
|
+
database_cleaner (1.3.0)
|
|
31
|
+
diff-lcs (1.2.5)
|
|
32
|
+
ffi (1.9.5)
|
|
33
|
+
flipper (0.7.0)
|
|
34
|
+
foreigner (1.7.4)
|
|
35
|
+
activerecord (>= 3.0.0)
|
|
36
|
+
formatador (0.2.5)
|
|
37
|
+
guard (2.6.1)
|
|
38
|
+
formatador (>= 0.2.4)
|
|
39
|
+
listen (~> 2.7)
|
|
40
|
+
lumberjack (~> 1.0)
|
|
41
|
+
pry (>= 0.9.12)
|
|
42
|
+
thor (>= 0.18.1)
|
|
43
|
+
guard-bundler (2.0.0)
|
|
44
|
+
bundler (~> 1.0)
|
|
45
|
+
guard (~> 2.2)
|
|
46
|
+
guard-rspec (4.3.1)
|
|
47
|
+
guard (~> 2.1)
|
|
48
|
+
rspec (>= 2.14, < 4.0)
|
|
49
|
+
hitimes (1.2.2)
|
|
50
|
+
i18n (0.7.0)
|
|
51
|
+
json (1.8.3)
|
|
52
|
+
listen (2.7.11)
|
|
53
|
+
celluloid (>= 0.15.2)
|
|
54
|
+
rb-fsevent (>= 0.9.3)
|
|
55
|
+
rb-inotify (>= 0.9)
|
|
56
|
+
lumberjack (1.0.9)
|
|
57
|
+
method_source (0.8.2)
|
|
58
|
+
minitest (5.8.0)
|
|
59
|
+
pg (0.17.1)
|
|
60
|
+
pry (0.10.1)
|
|
61
|
+
coderay (~> 1.1.0)
|
|
62
|
+
method_source (~> 0.8.1)
|
|
63
|
+
slop (~> 3.4)
|
|
64
|
+
rake (10.3.2)
|
|
65
|
+
rb-fsevent (0.9.4)
|
|
66
|
+
rb-inotify (0.9.5)
|
|
67
|
+
ffi (>= 0.5.0)
|
|
68
|
+
rspec (3.1.0)
|
|
69
|
+
rspec-core (~> 3.1.0)
|
|
70
|
+
rspec-expectations (~> 3.1.0)
|
|
71
|
+
rspec-mocks (~> 3.1.0)
|
|
72
|
+
rspec-core (3.1.5)
|
|
73
|
+
rspec-support (~> 3.1.0)
|
|
74
|
+
rspec-expectations (3.1.2)
|
|
75
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
76
|
+
rspec-support (~> 3.1.0)
|
|
77
|
+
rspec-mocks (3.1.2)
|
|
78
|
+
rspec-support (~> 3.1.0)
|
|
79
|
+
rspec-support (3.1.1)
|
|
80
|
+
slop (3.6.0)
|
|
81
|
+
thor (0.19.1)
|
|
82
|
+
thread_safe (0.3.5)
|
|
83
|
+
timecop (0.7.1)
|
|
84
|
+
timers (4.0.1)
|
|
85
|
+
hitimes
|
|
86
|
+
tzinfo (1.2.2)
|
|
87
|
+
thread_safe (~> 0.1)
|
|
88
|
+
|
|
89
|
+
PLATFORMS
|
|
90
|
+
ruby
|
|
91
|
+
|
|
92
|
+
DEPENDENCIES
|
|
93
|
+
database_cleaner
|
|
94
|
+
flipper-activerecord3dot2!
|
|
95
|
+
guard
|
|
96
|
+
guard-bundler
|
|
97
|
+
guard-rspec
|
|
98
|
+
pg
|
|
99
|
+
rake
|
|
100
|
+
rb-fsevent
|
|
101
|
+
rspec
|
|
102
|
+
timecop
|
|
103
|
+
|
|
104
|
+
BUNDLED WITH
|
|
105
|
+
1.10.2
|
data/Guardfile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# A sample Guardfile
|
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
|
3
|
+
|
|
4
|
+
guard 'bundler' do
|
|
5
|
+
watch('Gemfile')
|
|
6
|
+
watch(/^.+\.gemspec/)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
guard 'rspec', cmd: 'rspec' do
|
|
10
|
+
watch(%r{^spec/.+_spec\.rb$}) { "spec" }
|
|
11
|
+
watch(%r{^lib/(.+)\.rb$}) { "spec" }
|
|
12
|
+
watch('spec/helper.rb') { "spec" }
|
|
13
|
+
end
|
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014 Blake Gentry
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
data/README.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# Flipper ActiveRecord 3.2
|
|
2
|
+
|
|
3
|
+
An [ActiveRecord](https://github.com/rails/rails/tree/master/activerecord) adapter for [Flipper](https://github.com/jnunemaker/flipper).
|
|
4
|
+
|
|
5
|
+
This version targets Rails 3.2. For Rails 4 support, please see
|
|
6
|
+
[Flipper ActiveRecord](https://github.com/bgentry/flipper-activerecord)
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
Add this line to your application's Gemfile:
|
|
11
|
+
|
|
12
|
+
gem 'flipper-activerecord3dot2'
|
|
13
|
+
|
|
14
|
+
And then execute:
|
|
15
|
+
|
|
16
|
+
$ bundle
|
|
17
|
+
|
|
18
|
+
Or install it yourself with:
|
|
19
|
+
|
|
20
|
+
$ gem install flipper-activerecord3dot2
|
|
21
|
+
|
|
22
|
+
Generate a migration to create the required database tables:
|
|
23
|
+
|
|
24
|
+
$ rails g flipper:active_record
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
require 'flipper/adapters/activerecord'
|
|
30
|
+
adapter = Flipper::Adapters::ActiveRecord.new
|
|
31
|
+
flipper = Flipper.new(adapter)
|
|
32
|
+
# profit...
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Internals
|
|
36
|
+
|
|
37
|
+
Two database tables are used: `flipper_features` and `flipper_gates`.
|
|
38
|
+
|
|
39
|
+
A list of all available features is stored in the `flipper_features` table:
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
require 'flipper/adapters/activerecord'
|
|
43
|
+
|
|
44
|
+
adapter = Flipper::Adapters::ActiveRecord.new
|
|
45
|
+
flipper = Flipper.new(adapter)
|
|
46
|
+
|
|
47
|
+
# Register a few groups.
|
|
48
|
+
Flipper.register(:admins) { |thing| thing.admin? }
|
|
49
|
+
Flipper.register(:early_access) { |thing| thing.early_access? }
|
|
50
|
+
|
|
51
|
+
# Create a user class that has flipper_id instance method.
|
|
52
|
+
User = Struct.new(:flipper_id)
|
|
53
|
+
|
|
54
|
+
flipper[:stats].enable
|
|
55
|
+
flipper[:stats].enable flipper.group(:admins)
|
|
56
|
+
flipper[:stats].enable User.new('25')
|
|
57
|
+
flipper[:stats].enable User.new('90')
|
|
58
|
+
flipper[:stats].enable User.new('180')
|
|
59
|
+
flipper[:stats].enable flipper.random(15)
|
|
60
|
+
flipper[:stats].enable flipper.actors(45)
|
|
61
|
+
|
|
62
|
+
flipper[:awesomeness].enable
|
|
63
|
+
flipper[:awesomeness].enable flipper.group(:admins)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
print 'all features: '
|
|
67
|
+
pp Flipper::ActiveRecord::Feature.all
|
|
68
|
+
# Flipper::ActiveRecord::Feature Load (0.3ms) SELECT "flipper_features".* FROM "flipper_features"
|
|
69
|
+
# [#<Flipper::ActiveRecord::Feature:0x007fa883c6b578
|
|
70
|
+
# id: 1,
|
|
71
|
+
# name: "stats",
|
|
72
|
+
# created_at: Wed, 08 Oct 2014 07:21:27 UTC +00:00,
|
|
73
|
+
# updated_at: Wed, 08 Oct 2014 07:21:27 UTC +00:00>,
|
|
74
|
+
# #<Flipper::ActiveRecord::Feature:0x007fa883c6ada8
|
|
75
|
+
# id: 2,
|
|
76
|
+
# name: "awesomeness",
|
|
77
|
+
# created_at: Wed, 08 Oct 2014 07:21:38 UTC +00:00,
|
|
78
|
+
# updated_at: Wed, 08 Oct 2014 07:21:38 UTC +00:00>]
|
|
79
|
+
|
|
80
|
+
print 'all gates: '
|
|
81
|
+
pp Flipper::ActiveRecord::Gate.all
|
|
82
|
+
# Flipper::ActiveRecord::Gate Load (0.4ms) SELECT "flipper_gates".* FROM "flipper_gates"
|
|
83
|
+
# [#<Flipper::ActiveRecord::Gate:0x007fa883c42ab0
|
|
84
|
+
# id: 1,
|
|
85
|
+
# flipper_feature_id: 1,
|
|
86
|
+
# name: "boolean",
|
|
87
|
+
# value: "true",
|
|
88
|
+
# created_at: Wed, 08 Oct 2014 07:21:27 UTC +00:00,
|
|
89
|
+
# updated_at: Wed, 08 Oct 2014 07:21:27 UTC +00:00>,
|
|
90
|
+
# #<Flipper::ActiveRecord::Gate:0x007fa883c42290
|
|
91
|
+
# id: 2,
|
|
92
|
+
# flipper_feature_id: 1,
|
|
93
|
+
# name: "groups",
|
|
94
|
+
# value: "admins",
|
|
95
|
+
# created_at: Wed, 08 Oct 2014 07:21:31 UTC +00:00,
|
|
96
|
+
# updated_at: Wed, 08 Oct 2014 07:21:31 UTC +00:00>,
|
|
97
|
+
# #<Flipper::ActiveRecord::Gate:0x007fa883c41b10
|
|
98
|
+
# id: 3,
|
|
99
|
+
# flipper_feature_id: 1,
|
|
100
|
+
# name: "actors",
|
|
101
|
+
# value: "25",
|
|
102
|
+
# created_at: Wed, 08 Oct 2014 07:21:31 UTC +00:00,
|
|
103
|
+
# updated_at: Wed, 08 Oct 2014 07:21:31 UTC +00:00>,
|
|
104
|
+
# #<Flipper::ActiveRecord::Gate:0x007fa883c41408
|
|
105
|
+
# id: 4,
|
|
106
|
+
# flipper_feature_id: 1,
|
|
107
|
+
# name: "actors",
|
|
108
|
+
# value: "90",
|
|
109
|
+
# created_at: Wed, 08 Oct 2014 07:21:31 UTC +00:00,
|
|
110
|
+
# updated_at: Wed, 08 Oct 2014 07:21:31 UTC +00:00>,
|
|
111
|
+
# #<Flipper::ActiveRecord::Gate:0x007fa883c40c38
|
|
112
|
+
# id: 5,
|
|
113
|
+
# flipper_feature_id: 1,
|
|
114
|
+
# name: "actors",
|
|
115
|
+
# value: "180",
|
|
116
|
+
# created_at: Wed, 08 Oct 2014 07:21:31 UTC +00:00,
|
|
117
|
+
# updated_at: Wed, 08 Oct 2014 07:21:31 UTC +00:00>,
|
|
118
|
+
# #<Flipper::ActiveRecord::Gate:0x007fa883c40558
|
|
119
|
+
# id: 6,
|
|
120
|
+
# flipper_feature_id: 1,
|
|
121
|
+
# name: "percentage_of_random",
|
|
122
|
+
# value: "15",
|
|
123
|
+
# created_at: Wed, 08 Oct 2014 07:21:38 UTC +00:00,
|
|
124
|
+
# updated_at: Wed, 08 Oct 2014 07:21:38 UTC +00:00>,
|
|
125
|
+
# #<Flipper::ActiveRecord::Gate:0x007fa883c3bda0
|
|
126
|
+
# id: 7,
|
|
127
|
+
# flipper_feature_id: 1,
|
|
128
|
+
# name: "percentage_of_actors",
|
|
129
|
+
# value: "45",
|
|
130
|
+
# created_at: Wed, 08 Oct 2014 07:21:38 UTC +00:00,
|
|
131
|
+
# updated_at: Wed, 08 Oct 2014 07:21:38 UTC +00:00>,
|
|
132
|
+
# #<Flipper::ActiveRecord::Gate:0x007fa883c3b5f8
|
|
133
|
+
# id: 8,
|
|
134
|
+
# flipper_feature_id: 2,
|
|
135
|
+
# name: "boolean",
|
|
136
|
+
# value: "true",
|
|
137
|
+
# created_at: Wed, 08 Oct 2014 07:21:38 UTC +00:00,
|
|
138
|
+
# updated_at: Wed, 08 Oct 2014 07:21:38 UTC +00:00>,
|
|
139
|
+
# #<Flipper::ActiveRecord::Gate:0x007fa883c3afe0
|
|
140
|
+
# id: 9,
|
|
141
|
+
# flipper_feature_id: 2,
|
|
142
|
+
# name: "groups",
|
|
143
|
+
# value: "admins",
|
|
144
|
+
# created_at: Wed, 08 Oct 2014 07:21:39 UTC +00:00,
|
|
145
|
+
# updated_at: Wed, 08 Oct 2014 07:21:39 UTC +00:00>]
|
|
146
|
+
|
|
147
|
+
puts 'flipper get of feature'
|
|
148
|
+
pp adapter.get(flipper[:stats])
|
|
149
|
+
# flipper get of feature
|
|
150
|
+
# SQL (0.6ms) SELECT DISTINCT "flipper_features"."id" FROM "flipper_features" LEFT OUTER JOIN "flipper_gates" ON "flipper_gates"."flipper_feature_id" = "flipper_features"."id" WHERE "flipper_features"."name" = $1 LIMIT 1 [["name", "stats"]]
|
|
151
|
+
# SQL (0.3ms) SELECT "flipper_features"."id" AS t0_r0, "flipper_features"."name" AS t0_r1, "flipper_features"."created_at" AS t0_r2, "flipper_features"."updated_at" AS t0_r3, "flipper_gates"."id" AS t1_r0, "flipper_gates"."flipper_feature_id" AS t1_r1, "flipper_gates"."name" AS t1_r2, "flipper_gates"."value" AS t1_r3, "flipper_gates"."created_at" AS t1_r4, "flipper_gates"."updated_at" AS t1_r5 FROM "flipper_features" LEFT OUTER JOIN "flipper_gates" ON "flipper_gates"."flipper_feature_id" = "flipper_features"."id" WHERE "flipper_features"."name" = $1 AND "flipper_features"."id" IN (1) [["name", "stats"]]
|
|
152
|
+
# {:boolean=>"true",
|
|
153
|
+
# :groups=>#<Set: {"admins"}>,
|
|
154
|
+
# :actors=>#<Set: {"25", "90", "180"}>,
|
|
155
|
+
# :percentage_of_actors=>"45",
|
|
156
|
+
# :percentage_of_random=>"15"}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Testing
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
createdb flipper_activerecord_test
|
|
163
|
+
rspec
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Contributing
|
|
167
|
+
|
|
168
|
+
1. Fork it
|
|
169
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
170
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
|
171
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
172
|
+
5. Create new Pull Request
|
|
173
|
+
|
|
174
|
+
## Thanks
|
|
175
|
+
|
|
176
|
+
Thanks to John Nunemaker for making Flipper and its adapters!
|
data/Rakefile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Gem::Specification.new do |gem|
|
|
2
|
+
gem.name = "flipper-activerecord3dot2"
|
|
3
|
+
gem.version = "0.1.2"
|
|
4
|
+
gem.authors = ["Jesse Proudman", "Blake Gentry"]
|
|
5
|
+
gem.email = ["jproudman@bluebox.net", "blakesgentry@gmail.com"]
|
|
6
|
+
gem.description = %q{ActiveRecord 3.2 adapter for Flipper}
|
|
7
|
+
gem.summary = <<-SUMMARY
|
|
8
|
+
A fork of flipper-activerecord which supports ActiveRecord 3.2 and ActiveRecord 4.1 with minimal changes.
|
|
9
|
+
SUMMARY
|
|
10
|
+
gem.homepage = "https://github.com/jproudman/flipper-activerecord"
|
|
11
|
+
gem.require_paths = ["lib"]
|
|
12
|
+
|
|
13
|
+
gem.files = `git ls-files`.split(" ")
|
|
14
|
+
gem.add_dependency 'flipper', '~> 0.6'
|
|
15
|
+
gem.add_runtime_dependency 'activerecord', '>= 3.2.21', '< 4.2'
|
|
16
|
+
gem.add_runtime_dependency 'foreigner', '~> 1.7', '>= 1.7.4'
|
|
17
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'flipper/adapters/activerecord'
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
require 'set'
|
|
2
|
+
require 'flipper'
|
|
3
|
+
require 'active_record'
|
|
4
|
+
|
|
5
|
+
require 'flipper/activerecord/feature'
|
|
6
|
+
require 'flipper/activerecord/gate'
|
|
7
|
+
|
|
8
|
+
module Flipper
|
|
9
|
+
module Adapters
|
|
10
|
+
class ActiveRecord
|
|
11
|
+
include Flipper::Adapter
|
|
12
|
+
|
|
13
|
+
# Public: The name of the adapter.
|
|
14
|
+
attr_reader :name
|
|
15
|
+
|
|
16
|
+
def initialize
|
|
17
|
+
@name = :activerecord
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Public: The set of known features.
|
|
21
|
+
def features
|
|
22
|
+
Flipper::ActiveRecord::Feature.select(:name).map(&:name).to_set
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Public: Adds a feature to the set of known features.
|
|
26
|
+
def add(feature)
|
|
27
|
+
opts = { name: feature.name.to_s }
|
|
28
|
+
Flipper::ActiveRecord::Feature.where(opts).first ||
|
|
29
|
+
Flipper::ActiveRecord::Feature.create!(opts)
|
|
30
|
+
true
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Public: Removes a feature from the set of known features.
|
|
34
|
+
def remove(feature)
|
|
35
|
+
clear(feature)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Public: Clears all the gate values for a feature.
|
|
39
|
+
def clear(feature)
|
|
40
|
+
Flipper::ActiveRecord::Feature.where(name: feature.key).destroy_all
|
|
41
|
+
true
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Public: Gets the values for all gates for a given feature.
|
|
45
|
+
#
|
|
46
|
+
# Returns a Hash of Flipper::Gate#key => value.
|
|
47
|
+
def get(feature)
|
|
48
|
+
result = {}
|
|
49
|
+
f = Flipper::ActiveRecord::Feature.eager_load(:gates).where(name: feature.key).first
|
|
50
|
+
|
|
51
|
+
feature.gates.each do |gate|
|
|
52
|
+
result[gate.key] = case gate.data_type
|
|
53
|
+
when :boolean, :integer
|
|
54
|
+
if f
|
|
55
|
+
g = f.gates.detect {|g| g.name == gate.key.to_s}
|
|
56
|
+
g.value if g
|
|
57
|
+
end
|
|
58
|
+
when :set
|
|
59
|
+
if f
|
|
60
|
+
f.gates.select {|g| g.name == gate.key.to_s}.map{|g| g.value }.to_set
|
|
61
|
+
else
|
|
62
|
+
Set.new
|
|
63
|
+
end
|
|
64
|
+
else
|
|
65
|
+
unsupported_data_type gate.data_type
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
result
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Public: Enables a gate for a given thing.
|
|
73
|
+
#
|
|
74
|
+
# feature - The Flipper::Feature for the gate.
|
|
75
|
+
# gate - The Flipper::Gate to disable.
|
|
76
|
+
# thing - The Flipper::Type being disabled for the gate.
|
|
77
|
+
#
|
|
78
|
+
# Returns true.
|
|
79
|
+
def enable(feature, gate, thing)
|
|
80
|
+
case gate.data_type
|
|
81
|
+
when :boolean, :integer
|
|
82
|
+
g = gate_join( feature )
|
|
83
|
+
opts = { name: gate.key.to_s }
|
|
84
|
+
g = g.where(opts).first || g.new(opts)
|
|
85
|
+
g.value = thing.value.to_s
|
|
86
|
+
unless g.persisted?
|
|
87
|
+
g.feature = feature_id( feature )
|
|
88
|
+
end
|
|
89
|
+
g.save!
|
|
90
|
+
when :set
|
|
91
|
+
g = gate_join( feature )
|
|
92
|
+
opts = { name: gate.key.to_s, value: thing.value.to_s }
|
|
93
|
+
g = g.where(opts).first || g.new(opts)
|
|
94
|
+
unless g.persisted?
|
|
95
|
+
g.feature = feature_id( feature )
|
|
96
|
+
end
|
|
97
|
+
g.save!
|
|
98
|
+
else
|
|
99
|
+
unsupported_data_type gate.data_type
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
true
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Public: Disables a gate for a given thing.
|
|
106
|
+
#
|
|
107
|
+
# feature - The Flipper::Feature for the gate.
|
|
108
|
+
# gate - The Flipper::Gate to disable.
|
|
109
|
+
# thing - The Flipper::Type being disabled for the gate.
|
|
110
|
+
#
|
|
111
|
+
# Returns true.
|
|
112
|
+
def disable(feature, gate, thing)
|
|
113
|
+
scope = gate_join(feature)
|
|
114
|
+
|
|
115
|
+
g = case gate.data_type
|
|
116
|
+
when :boolean
|
|
117
|
+
scope.destroy_all
|
|
118
|
+
when :integer
|
|
119
|
+
scope.where(name: gate.key.to_s).limit(1).
|
|
120
|
+
update_all(value: thing.value.to_s)
|
|
121
|
+
when :set
|
|
122
|
+
scope.where(name: gate.key.to_s, value: thing.value.to_s).destroy_all
|
|
123
|
+
else
|
|
124
|
+
unsupported_data_type gate.data_type
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
true
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Private
|
|
131
|
+
def feature_id( feature )
|
|
132
|
+
opts = { name: feature.key }
|
|
133
|
+
i = Flipper::ActiveRecord::Feature.select(:id)
|
|
134
|
+
i.where(opts).first || i.create!(opts)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Private
|
|
138
|
+
def gate_join( feature )
|
|
139
|
+
Flipper::ActiveRecord::Gate.joins(:feature).where( flipper_features: {name: feature.key} ).readonly(false)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# Private
|
|
143
|
+
def unsupported_data_type(data_type)
|
|
144
|
+
raise "#{data_type} is not supported by this adapter"
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'rails/generators/base'
|
|
2
|
+
require "rails/generators/migration"
|
|
3
|
+
require "rails/generators/active_record"
|
|
4
|
+
|
|
5
|
+
# Extend Rails::Generators::Base so that it creates an AR migration
|
|
6
|
+
module Flipper
|
|
7
|
+
class ActiveRecordGenerator < Rails::Generators::Base
|
|
8
|
+
include Rails::Generators::Migration
|
|
9
|
+
desc "This generator creates a migration to create Flipper ActiveRecord tables."
|
|
10
|
+
|
|
11
|
+
source_paths << File.join(File.dirname(__FILE__), "templates")
|
|
12
|
+
|
|
13
|
+
def create_migration_file
|
|
14
|
+
migration_template "migration.rb", "db/migrate/create_flipper_tables.rb"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.next_migration_number(dirname)
|
|
18
|
+
::ActiveRecord::Generators::Base.next_migration_number dirname
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# This is necessary because if you don't include foreigner in your
|
|
2
|
+
# gemfile it won't load during a migration, for some reason.
|
|
3
|
+
require 'foreigner'; Foreigner.load
|
|
4
|
+
|
|
5
|
+
class CreateFlipperTables < ActiveRecord::Migration
|
|
6
|
+
def self.up
|
|
7
|
+
create_table :flipper_features do |t|
|
|
8
|
+
t.string :name, null: false
|
|
9
|
+
t.timestamps null: false
|
|
10
|
+
end
|
|
11
|
+
add_index :flipper_features, :name, unique: true
|
|
12
|
+
|
|
13
|
+
create_table :flipper_gates do |t|
|
|
14
|
+
t.integer :flipper_feature_id, null: false
|
|
15
|
+
t.string :name, null: false
|
|
16
|
+
t.string :value
|
|
17
|
+
t.timestamps null: false
|
|
18
|
+
end
|
|
19
|
+
add_foreign_key :flipper_gates, :flipper_features, on_delete: :cascade
|
|
20
|
+
add_index :flipper_gates, [:flipper_feature_id, :name, :value], unique: true
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.down
|
|
24
|
+
remove_foreign_key :flipper_gates, :flipper_features
|
|
25
|
+
drop_table :flipper_gates
|
|
26
|
+
drop_table :flipper_features
|
|
27
|
+
end
|
|
28
|
+
end
|
data/script/release
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
#/ Usage: release
|
|
3
|
+
#/
|
|
4
|
+
#/ Tag the version in the repo and push the gem.
|
|
5
|
+
#/
|
|
6
|
+
|
|
7
|
+
set -e
|
|
8
|
+
cd $(dirname "$0")/..
|
|
9
|
+
|
|
10
|
+
[ "$1" = "--help" -o "$1" = "-h" -o "$1" = "help" ] && {
|
|
11
|
+
grep '^#/' <"$0"| cut -c4-
|
|
12
|
+
exit 0
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
gem_name=flipper-activerecord
|
|
16
|
+
|
|
17
|
+
# Build a new gem archive.
|
|
18
|
+
rm -rf $gem_name-*.gem
|
|
19
|
+
gem build -q $gem_name.gemspec
|
|
20
|
+
|
|
21
|
+
# Make sure we're on the master branch.
|
|
22
|
+
(git branch | grep -q '* master') || {
|
|
23
|
+
echo "Only release from the master branch."
|
|
24
|
+
exit 1
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
# Figure out what version we're releasing.
|
|
28
|
+
tag=v`ls $gem_name-*.gem | sed "s/^$gem_name-\(.*\)\.gem$/\1/"`
|
|
29
|
+
|
|
30
|
+
echo "Releasing $tag"
|
|
31
|
+
|
|
32
|
+
# Make sure we haven't released this version before.
|
|
33
|
+
git fetch -t origin
|
|
34
|
+
|
|
35
|
+
(git tag -l | grep -q "$tag") && {
|
|
36
|
+
echo "Whoops, there's already a '${tag}' tag."
|
|
37
|
+
exit 1
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
# Tag it and bag it.
|
|
41
|
+
gem push $gem_name-*.gem && git tag "$tag" &&
|
|
42
|
+
git push origin master && git push origin "$tag"
|
data/spec/database.yml
ADDED
data/spec/helper.rb
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
$:.unshift(File.expand_path('../../lib', __FILE__))
|
|
2
|
+
|
|
3
|
+
require 'bundler'
|
|
4
|
+
Bundler.setup :default
|
|
5
|
+
require 'yaml'
|
|
6
|
+
require 'flipper-activerecord'
|
|
7
|
+
require 'database_cleaner'
|
|
8
|
+
|
|
9
|
+
ENV["RAILS_ENV"] = "test"
|
|
10
|
+
config = YAML.load(File.read("spec/database.yml"))
|
|
11
|
+
|
|
12
|
+
ActiveRecord::Base.establish_connection config["postgresql"]
|
|
13
|
+
ActiveRecord::Migration.verbose = true
|
|
14
|
+
|
|
15
|
+
require 'generators/flipper/templates/migration'
|
|
16
|
+
ActiveRecord::Schema.define do
|
|
17
|
+
CreateFlipperTables.up
|
|
18
|
+
|
|
19
|
+
# create_table :stories, primary_key: :story_id, force: true do |table|
|
|
20
|
+
# table.string :text
|
|
21
|
+
# table.boolean :scoped, default: true
|
|
22
|
+
# end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Add this directory so the ActiveSupport autoloading works
|
|
26
|
+
ActiveSupport::Dependencies.autoload_paths << File.dirname(__FILE__)
|
|
27
|
+
|
|
28
|
+
RSpec.configure do |config|
|
|
29
|
+
config.filter_run :focused => true
|
|
30
|
+
config.alias_example_to :fit, :focused => true
|
|
31
|
+
config.alias_example_to :xit, :pending => true
|
|
32
|
+
config.run_all_when_everything_filtered = true
|
|
33
|
+
config.fail_fast = true
|
|
34
|
+
|
|
35
|
+
config.backtrace_exclusion_patterns = [
|
|
36
|
+
/rspec-(core|expectations)/,
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
config.before(:suite) do
|
|
40
|
+
DatabaseCleaner.strategy = :transaction
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
config.before(:each) do
|
|
44
|
+
DatabaseCleaner.start
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
config.after(:each) do
|
|
48
|
+
DatabaseCleaner.clean
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
config.after(:suite) do
|
|
52
|
+
ActiveRecord::Schema.define do
|
|
53
|
+
CreateFlipperTables.down
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
metadata
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: flipper-activerecord3dot2
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 0.1.2
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- Jesse Proudman
|
|
@@ -10,12 +9,11 @@ authors:
|
|
|
10
9
|
autorequire:
|
|
11
10
|
bindir: bin
|
|
12
11
|
cert_chain: []
|
|
13
|
-
date: 2015-
|
|
12
|
+
date: 2015-08-27 00:00:00.000000000 Z
|
|
14
13
|
dependencies:
|
|
15
14
|
- !ruby/object:Gem::Dependency
|
|
16
15
|
name: flipper
|
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
|
18
|
-
none: false
|
|
19
17
|
requirements:
|
|
20
18
|
- - ~>
|
|
21
19
|
- !ruby/object:Gem::Version
|
|
@@ -23,7 +21,6 @@ dependencies:
|
|
|
23
21
|
type: :runtime
|
|
24
22
|
prerelease: false
|
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
-
none: false
|
|
27
24
|
requirements:
|
|
28
25
|
- - ~>
|
|
29
26
|
- !ruby/object:Gem::Version
|
|
@@ -31,35 +28,43 @@ dependencies:
|
|
|
31
28
|
- !ruby/object:Gem::Dependency
|
|
32
29
|
name: activerecord
|
|
33
30
|
requirement: !ruby/object:Gem::Requirement
|
|
34
|
-
none: false
|
|
35
31
|
requirements:
|
|
36
|
-
- -
|
|
32
|
+
- - '>='
|
|
37
33
|
- !ruby/object:Gem::Version
|
|
38
34
|
version: 3.2.21
|
|
35
|
+
- - <
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '4.2'
|
|
39
38
|
type: :runtime
|
|
40
39
|
prerelease: false
|
|
41
40
|
version_requirements: !ruby/object:Gem::Requirement
|
|
42
|
-
none: false
|
|
43
41
|
requirements:
|
|
44
|
-
- -
|
|
42
|
+
- - '>='
|
|
45
43
|
- !ruby/object:Gem::Version
|
|
46
44
|
version: 3.2.21
|
|
45
|
+
- - <
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '4.2'
|
|
47
48
|
- !ruby/object:Gem::Dependency
|
|
48
49
|
name: foreigner
|
|
49
50
|
requirement: !ruby/object:Gem::Requirement
|
|
50
|
-
none: false
|
|
51
51
|
requirements:
|
|
52
|
-
- -
|
|
52
|
+
- - ~>
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
54
|
+
version: '1.7'
|
|
55
|
+
- - '>='
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: 1.7.4
|
|
55
58
|
type: :runtime
|
|
56
59
|
prerelease: false
|
|
57
60
|
version_requirements: !ruby/object:Gem::Requirement
|
|
58
|
-
none: false
|
|
59
61
|
requirements:
|
|
60
|
-
- -
|
|
62
|
+
- - ~>
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
version: '1.7'
|
|
65
|
+
- - '>='
|
|
61
66
|
- !ruby/object:Gem::Version
|
|
62
|
-
version:
|
|
67
|
+
version: 1.7.4
|
|
63
68
|
description: ActiveRecord 3.2 adapter for Flipper
|
|
64
69
|
email:
|
|
65
70
|
- jproudman@bluebox.net
|
|
@@ -67,29 +72,49 @@ email:
|
|
|
67
72
|
executables: []
|
|
68
73
|
extensions: []
|
|
69
74
|
extra_rdoc_files: []
|
|
70
|
-
files:
|
|
75
|
+
files:
|
|
76
|
+
- .gitignore
|
|
77
|
+
- .travis.yml
|
|
78
|
+
- Gemfile
|
|
79
|
+
- Gemfile.lock
|
|
80
|
+
- Guardfile
|
|
81
|
+
- LICENSE
|
|
82
|
+
- README.md
|
|
83
|
+
- Rakefile
|
|
84
|
+
- flipper-activerecord3dot2.gemspec
|
|
85
|
+
- lib/flipper-activerecord.rb
|
|
86
|
+
- lib/flipper/activerecord/feature.rb
|
|
87
|
+
- lib/flipper/activerecord/gate.rb
|
|
88
|
+
- lib/flipper/adapters/activerecord.rb
|
|
89
|
+
- lib/flipper/adapters/activerecord/version.rb
|
|
90
|
+
- lib/generators/flipper/active_record_generator.rb
|
|
91
|
+
- lib/generators/flipper/templates/migration.rb
|
|
92
|
+
- script/release
|
|
93
|
+
- spec/activerecord_spec.rb
|
|
94
|
+
- spec/database.yml
|
|
95
|
+
- spec/helper.rb
|
|
71
96
|
homepage: https://github.com/jproudman/flipper-activerecord
|
|
72
97
|
licenses: []
|
|
98
|
+
metadata: {}
|
|
73
99
|
post_install_message:
|
|
74
100
|
rdoc_options: []
|
|
75
101
|
require_paths:
|
|
76
102
|
- lib
|
|
77
103
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
|
-
none: false
|
|
79
104
|
requirements:
|
|
80
|
-
- -
|
|
105
|
+
- - '>='
|
|
81
106
|
- !ruby/object:Gem::Version
|
|
82
107
|
version: '0'
|
|
83
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
|
-
none: false
|
|
85
109
|
requirements:
|
|
86
|
-
- -
|
|
110
|
+
- - '>='
|
|
87
111
|
- !ruby/object:Gem::Version
|
|
88
112
|
version: '0'
|
|
89
113
|
requirements: []
|
|
90
114
|
rubyforge_project:
|
|
91
|
-
rubygems_version:
|
|
115
|
+
rubygems_version: 2.0.14
|
|
92
116
|
signing_key:
|
|
93
|
-
specification_version:
|
|
94
|
-
summary: ActiveRecord 3.2
|
|
117
|
+
specification_version: 4
|
|
118
|
+
summary: A fork of flipper-activerecord which supports ActiveRecord 3.2 and ActiveRecord
|
|
119
|
+
4.1 with minimal changes.
|
|
95
120
|
test_files: []
|