flipper-activerecord 0.1.3 → 1.0.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
- SHA1:
3
- metadata.gz: 4a5784ed7d6b6448b056465435e6a89f9d56f079
4
- data.tar.gz: 18aa440084c845d8dbcb980f22be333de0b6c287
2
+ SHA256:
3
+ metadata.gz: 25b849b9b8ccfd3abbc2af7ab9c20dd451581c3e45a4781415b8502b6c817178
4
+ data.tar.gz: 6c4b4ca89957784249bc0fde5c2277a0009ed4b646a11f0a844799571e9ead2b
5
5
  SHA512:
6
- metadata.gz: 5cd36dea986885c1a9f2ad031697d3e39df200e0dbd199a83a500d1e542c411454f31b6185fc55554e5f1ed780bde943ec7e0c0eef802f91be2eccf790690ff9
7
- data.tar.gz: 1a3caa4a68b5ac6d38ebdeedc0fca12ad021f7d5ee3ec4a4bbab9335c326a7c36b574c7757ab961750c604d4a37f1c53b5402526675d000e2c5be48a542057a7
6
+ metadata.gz: 872aaf0402d3b9c9068f967b0131064d334758caa59eeec971f63b3ee5492fc6f572366397fc1293ea49dd505eec5d55399f47afd9dee52bcde9e0b5ed1b8a2d
7
+ data.tar.gz: ccd44a4963dd5c91318f28f942556d155501652da689904ba5986ef1d8463eceb26d017a0487e978ebafad76a0fd9d1d6da6adc0369eacdcc04e0c792a8dd93d
data/Gemfile CHANGED
@@ -1,15 +1,2 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
-
4
- gem 'database_cleaner'
5
- gem 'pg'
6
- gem 'rake'
7
- gem 'rspec'
8
- gem 'timecop'
9
-
10
- group(:guard) do
11
- gem 'guard'
12
- gem 'guard-rspec'
13
- gem 'guard-bundler'
14
- gem 'rb-fsevent'
15
- end
data/Gemfile.lock CHANGED
@@ -1,102 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- flipper-activerecord (0.1.2)
5
- activerecord (~> 4.2)
6
- flipper (~> 0.6)
4
+ flipper-activerecord (1.0.0)
7
5
 
8
6
  GEM
9
7
  remote: https://rubygems.org/
10
8
  specs:
11
- activemodel (4.2.5.1)
12
- activesupport (= 4.2.5.1)
13
- builder (~> 3.1)
14
- activerecord (4.2.5.1)
15
- activemodel (= 4.2.5.1)
16
- activesupport (= 4.2.5.1)
17
- arel (~> 6.0)
18
- activesupport (4.2.5.1)
19
- i18n (~> 0.7)
20
- json (~> 1.7, >= 1.7.7)
21
- minitest (~> 5.1)
22
- thread_safe (~> 0.3, >= 0.3.4)
23
- tzinfo (~> 1.1)
24
- arel (6.0.3)
25
- builder (3.2.2)
26
- celluloid (0.16.0)
27
- timers (~> 4.0.0)
28
- coderay (1.1.0)
29
- database_cleaner (1.3.0)
30
- diff-lcs (1.2.5)
31
- ffi (1.9.5)
32
- flipper (0.7.4)
33
- formatador (0.2.5)
34
- guard (2.6.1)
35
- formatador (>= 0.2.4)
36
- listen (~> 2.7)
37
- lumberjack (~> 1.0)
38
- pry (>= 0.9.12)
39
- thor (>= 0.18.1)
40
- guard-bundler (2.0.0)
41
- bundler (~> 1.0)
42
- guard (~> 2.2)
43
- guard-rspec (4.3.1)
44
- guard (~> 2.1)
45
- rspec (>= 2.14, < 4.0)
46
- hitimes (1.2.2)
47
- i18n (0.7.0)
48
- json (1.8.3)
49
- listen (2.7.11)
50
- celluloid (>= 0.15.2)
51
- rb-fsevent (>= 0.9.3)
52
- rb-inotify (>= 0.9)
53
- lumberjack (1.0.9)
54
- method_source (0.8.2)
55
- minitest (5.8.4)
56
- pg (0.17.1)
57
- pry (0.10.1)
58
- coderay (~> 1.1.0)
59
- method_source (~> 0.8.1)
60
- slop (~> 3.4)
61
- rake (10.3.2)
62
- rb-fsevent (0.9.4)
63
- rb-inotify (0.9.5)
64
- ffi (>= 0.5.0)
65
- rspec (3.1.0)
66
- rspec-core (~> 3.1.0)
67
- rspec-expectations (~> 3.1.0)
68
- rspec-mocks (~> 3.1.0)
69
- rspec-core (3.1.5)
70
- rspec-support (~> 3.1.0)
71
- rspec-expectations (3.1.2)
72
- diff-lcs (>= 1.2.0, < 2.0)
73
- rspec-support (~> 3.1.0)
74
- rspec-mocks (3.1.2)
75
- rspec-support (~> 3.1.0)
76
- rspec-support (3.1.1)
77
- slop (3.6.0)
78
- thor (0.19.1)
79
- thread_safe (0.3.5)
80
- timecop (0.7.1)
81
- timers (4.0.1)
82
- hitimes
83
- tzinfo (1.2.2)
84
- thread_safe (~> 0.1)
85
9
 
86
10
  PLATFORMS
87
11
  ruby
88
12
 
89
13
  DEPENDENCIES
90
- database_cleaner
91
14
  flipper-activerecord!
92
- guard
93
- guard-bundler
94
- guard-rspec
95
- pg
96
- rake
97
- rb-fsevent
98
- rspec
99
- timecop
100
15
 
101
16
  BUNDLED WITH
102
- 1.11.2
17
+ 2.4.4
data/README.md CHANGED
@@ -1,178 +1,5 @@
1
- # Flipper ActiveRecord
1
+ ## Deprecated
2
2
 
3
- An [ActiveRecord](https://github.com/rails/rails/tree/master/activerecord) adapter for [Flipper](https://github.com/jnunemaker/flipper).
3
+ The [Flipper](https://github.com/jnunemaker/flipper) project now includes its own ActiveRecord and Sequel adapters. It is recommended that all users migrate to the first-party adapter as I will not be supporting my own version any longer.
4
4
 
5
- Currently, this targets Rails 4.2 because it uses real foreign keys via
6
- `add_foreign_key` and `remove_foreign_key`.
7
-
8
- For users requiring Rails 3.2 support, please see: [Flipper ActiveRecord 3.2](https://github.com/blueboxjesse/flipper-activerecord).
9
-
10
- ## Installation
11
-
12
- Add this line to your application's Gemfile:
13
-
14
- gem 'flipper-activerecord'
15
-
16
- And then execute:
17
-
18
- $ bundle
19
-
20
- Or install it yourself with:
21
-
22
- $ gem install flipper-activerecord
23
-
24
- Generate a migration to create the required database tables:
25
-
26
- $ rails g flipper:active_record
27
-
28
- ## Usage
29
-
30
- ```ruby
31
- require 'flipper/adapters/activerecord'
32
- adapter = Flipper::Adapters::ActiveRecord.new
33
- flipper = Flipper.new(adapter)
34
- # profit...
35
- ```
36
-
37
- ## Internals
38
-
39
- Two database tables are used: `flipper_features` and `flipper_gates`.
40
-
41
- A list of all available features is stored in the `flipper_features` table:
42
-
43
- ```ruby
44
- require 'flipper/adapters/activerecord'
45
-
46
- adapter = Flipper::Adapters::ActiveRecord.new
47
- flipper = Flipper.new(adapter)
48
-
49
- # Register a few groups.
50
- Flipper.register(:admins) { |thing| thing.admin? }
51
- Flipper.register(:early_access) { |thing| thing.early_access? }
52
-
53
- # Create a user class that has flipper_id instance method.
54
- User = Struct.new(:flipper_id)
55
-
56
- flipper[:stats].enable
57
- flipper[:stats].enable flipper.group(:admins)
58
- flipper[:stats].enable User.new('25')
59
- flipper[:stats].enable User.new('90')
60
- flipper[:stats].enable User.new('180')
61
- flipper[:stats].enable flipper.random(15)
62
- flipper[:stats].enable flipper.actors(45)
63
-
64
- flipper[:awesomeness].enable
65
- flipper[:awesomeness].enable flipper.group(:admins)
66
-
67
-
68
- print 'all features: '
69
- pp Flipper::ActiveRecord::Feature.all
70
- # Flipper::ActiveRecord::Feature Load (0.3ms) SELECT "flipper_features".* FROM "flipper_features"
71
- # [#<Flipper::ActiveRecord::Feature:0x007fa883c6b578
72
- # id: 1,
73
- # name: "stats",
74
- # created_at: Wed, 08 Oct 2014 07:21:27 UTC +00:00,
75
- # updated_at: Wed, 08 Oct 2014 07:21:27 UTC +00:00>,
76
- # #<Flipper::ActiveRecord::Feature:0x007fa883c6ada8
77
- # id: 2,
78
- # name: "awesomeness",
79
- # created_at: Wed, 08 Oct 2014 07:21:38 UTC +00:00,
80
- # updated_at: Wed, 08 Oct 2014 07:21:38 UTC +00:00>]
81
-
82
- print 'all gates: '
83
- pp Flipper::ActiveRecord::Gate.all
84
- # Flipper::ActiveRecord::Gate Load (0.4ms) SELECT "flipper_gates".* FROM "flipper_gates"
85
- # [#<Flipper::ActiveRecord::Gate:0x007fa883c42ab0
86
- # id: 1,
87
- # flipper_feature_id: 1,
88
- # name: "boolean",
89
- # value: "true",
90
- # created_at: Wed, 08 Oct 2014 07:21:27 UTC +00:00,
91
- # updated_at: Wed, 08 Oct 2014 07:21:27 UTC +00:00>,
92
- # #<Flipper::ActiveRecord::Gate:0x007fa883c42290
93
- # id: 2,
94
- # flipper_feature_id: 1,
95
- # name: "groups",
96
- # value: "admins",
97
- # created_at: Wed, 08 Oct 2014 07:21:31 UTC +00:00,
98
- # updated_at: Wed, 08 Oct 2014 07:21:31 UTC +00:00>,
99
- # #<Flipper::ActiveRecord::Gate:0x007fa883c41b10
100
- # id: 3,
101
- # flipper_feature_id: 1,
102
- # name: "actors",
103
- # value: "25",
104
- # created_at: Wed, 08 Oct 2014 07:21:31 UTC +00:00,
105
- # updated_at: Wed, 08 Oct 2014 07:21:31 UTC +00:00>,
106
- # #<Flipper::ActiveRecord::Gate:0x007fa883c41408
107
- # id: 4,
108
- # flipper_feature_id: 1,
109
- # name: "actors",
110
- # value: "90",
111
- # created_at: Wed, 08 Oct 2014 07:21:31 UTC +00:00,
112
- # updated_at: Wed, 08 Oct 2014 07:21:31 UTC +00:00>,
113
- # #<Flipper::ActiveRecord::Gate:0x007fa883c40c38
114
- # id: 5,
115
- # flipper_feature_id: 1,
116
- # name: "actors",
117
- # value: "180",
118
- # created_at: Wed, 08 Oct 2014 07:21:31 UTC +00:00,
119
- # updated_at: Wed, 08 Oct 2014 07:21:31 UTC +00:00>,
120
- # #<Flipper::ActiveRecord::Gate:0x007fa883c40558
121
- # id: 6,
122
- # flipper_feature_id: 1,
123
- # name: "percentage_of_random",
124
- # value: "15",
125
- # created_at: Wed, 08 Oct 2014 07:21:38 UTC +00:00,
126
- # updated_at: Wed, 08 Oct 2014 07:21:38 UTC +00:00>,
127
- # #<Flipper::ActiveRecord::Gate:0x007fa883c3bda0
128
- # id: 7,
129
- # flipper_feature_id: 1,
130
- # name: "percentage_of_actors",
131
- # value: "45",
132
- # created_at: Wed, 08 Oct 2014 07:21:38 UTC +00:00,
133
- # updated_at: Wed, 08 Oct 2014 07:21:38 UTC +00:00>,
134
- # #<Flipper::ActiveRecord::Gate:0x007fa883c3b5f8
135
- # id: 8,
136
- # flipper_feature_id: 2,
137
- # name: "boolean",
138
- # value: "true",
139
- # created_at: Wed, 08 Oct 2014 07:21:38 UTC +00:00,
140
- # updated_at: Wed, 08 Oct 2014 07:21:38 UTC +00:00>,
141
- # #<Flipper::ActiveRecord::Gate:0x007fa883c3afe0
142
- # id: 9,
143
- # flipper_feature_id: 2,
144
- # name: "groups",
145
- # value: "admins",
146
- # created_at: Wed, 08 Oct 2014 07:21:39 UTC +00:00,
147
- # updated_at: Wed, 08 Oct 2014 07:21:39 UTC +00:00>]
148
-
149
- puts 'flipper get of feature'
150
- pp adapter.get(flipper[:stats])
151
- # flipper get of feature
152
- # 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"]]
153
- # 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"]]
154
- # {:boolean=>"true",
155
- # :groups=>#<Set: {"admins"}>,
156
- # :actors=>#<Set: {"25", "90", "180"}>,
157
- # :percentage_of_actors=>"45",
158
- # :percentage_of_random=>"15"}
159
- ```
160
-
161
- ## Testing
162
-
163
- ```
164
- dbcreate flipper_activerecord_test
165
- rspec
166
- ```
167
-
168
- ## Contributing
169
-
170
- 1. Fork it
171
- 2. Create your feature branch (`git checkout -b my-new-feature`)
172
- 3. Commit your changes (`git commit -am 'Added some feature'`)
173
- 4. Push to the branch (`git push origin my-new-feature`)
174
- 5. Create new Pull Request
175
-
176
- ## Thanks
177
-
178
- Thanks to John Nunemaker for making Flipper and its adapters!
5
+ [See 0.1.3 Release](https://github.com/bgentry/flipper-activerecord/tree/v0.1.3)
@@ -1,20 +1,16 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/flipper/adapters/activerecord/version', __FILE__)
3
-
4
2
  Gem::Specification.new do |gem|
5
3
  gem.name = "flipper-activerecord"
6
- gem.version = Flipper::Adapters::ActiveRecord::VERSION
4
+ gem.version = "1.0.0"
7
5
  gem.authors = ["Blake Gentry"]
8
6
  gem.email = ["blakesgentry@gmail.com"]
9
- gem.description = %q{ActiveRecord adapter for Flipper}
10
- gem.summary = %q{ActiveRecord adapter for Flipper}
7
+ gem.description = %q{DEPRECATED: use the official flipper-active_record adapter}
8
+ gem.summary = %q{DEPRECATED: use the official flipper-active_record adapter}
11
9
  gem.homepage = "https://github.com/bgentry/flipper-activerecord"
12
10
  gem.require_paths = ["lib"]
13
11
 
14
- gem.files = `git ls-files`.split($/)
15
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
12
+ separator = "*"*80
13
+ gem.post_install_message = "\n\n#{separator}\nflipper-activerecord is deprecated. Use flipper-active_record instead.\n#{separator}\n\n"
17
14
 
18
- gem.add_dependency 'flipper', '~> 0.6'
19
- gem.add_dependency 'activerecord', '~> 4.2'
15
+ gem.files = `git ls-files`.split($/)
20
16
  end
@@ -1 +1 @@
1
- require 'flipper/adapters/activerecord'
1
+ raise "flipper-activerecord is deprecated. Use the official flipper-active_record adapter."
metadata CHANGED
@@ -1,44 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flipper-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Gentry
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-09 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: flipper
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '0.6'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '0.6'
27
- - !ruby/object:Gem::Dependency
28
- name: activerecord
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '4.2'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '4.2'
41
- description: ActiveRecord adapter for Flipper
11
+ date: 2023-01-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'DEPRECATED: use the official flipper-active_record adapter'
42
14
  email:
43
15
  - blakesgentry@gmail.com
44
16
  executables: []
@@ -48,25 +20,21 @@ files:
48
20
  - ".gitignore"
49
21
  - Gemfile
50
22
  - Gemfile.lock
51
- - Guardfile
52
23
  - LICENSE
53
24
  - README.md
54
25
  - flipper-activerecord.gemspec
55
26
  - lib/flipper-activerecord.rb
56
- - lib/flipper/activerecord/feature.rb
57
- - lib/flipper/activerecord/gate.rb
58
- - lib/flipper/adapters/activerecord.rb
59
- - lib/flipper/adapters/activerecord/version.rb
60
- - lib/generators/flipper/active_record_generator.rb
61
- - lib/generators/flipper/templates/migration.rb
62
27
  - script/release
63
- - spec/activerecord_spec.rb
64
- - spec/database.yml
65
- - spec/helper.rb
66
28
  homepage: https://github.com/bgentry/flipper-activerecord
67
29
  licenses: []
68
30
  metadata: {}
69
- post_install_message:
31
+ post_install_message: |2+
32
+
33
+
34
+ ********************************************************************************
35
+ flipper-activerecord is deprecated. Use flipper-active_record instead.
36
+ ********************************************************************************
37
+
70
38
  rdoc_options: []
71
39
  require_paths:
72
40
  - lib
@@ -81,12 +49,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
49
  - !ruby/object:Gem::Version
82
50
  version: '0'
83
51
  requirements: []
84
- rubyforge_project:
85
- rubygems_version: 2.4.5.1
86
- signing_key:
52
+ rubygems_version: 3.3.7
53
+ signing_key:
87
54
  specification_version: 4
88
- summary: ActiveRecord adapter for Flipper
89
- test_files:
90
- - spec/activerecord_spec.rb
91
- - spec/database.yml
92
- - spec/helper.rb
55
+ summary: 'DEPRECATED: use the official flipper-active_record adapter'
56
+ test_files: []
57
+ ...
data/Guardfile DELETED
@@ -1,13 +0,0 @@
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
@@ -1,9 +0,0 @@
1
- module Flipper
2
- module ActiveRecord
3
- class Feature < ::ActiveRecord::Base
4
- self.table_name = "flipper_features"
5
-
6
- has_many :gates, foreign_key: "flipper_feature_id", :dependent => :destroy
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- module Flipper
2
- module ActiveRecord
3
- class Gate < ::ActiveRecord::Base
4
- self.table_name = "flipper_gates"
5
-
6
- belongs_to :feature, foreign_key: "flipper_feature_id"
7
- end
8
- end
9
- end
@@ -1,7 +0,0 @@
1
- module Flipper
2
- module Adapters
3
- class ActiveRecord
4
- VERSION = "0.1.3"
5
- end
6
- end
7
- end
@@ -1,142 +0,0 @@
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
- Flipper::ActiveRecord::Feature.find_or_create_by!(name: feature.name.to_s)
28
- true
29
- end
30
-
31
- # Public: Removes a feature from the set of known features.
32
- def remove(feature)
33
- Flipper::ActiveRecord::Feature.where(name: feature.key).destroy_all
34
- true
35
- end
36
-
37
- # Public: Clears all the gate values for a feature.
38
- def clear(feature)
39
- f = Flipper::ActiveRecord::Feature.find_by(name: feature.key)
40
- f.gates.destroy_all if f
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).find_by(name: feature.key)
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 = Flipper::ActiveRecord::Gate.joins(:feature).
83
- where(flipper_features: {name: feature.key}).
84
- find_or_initialize_by({
85
- name: gate.key.to_s,
86
- })
87
- g.value = thing.value.to_s
88
- unless g.persisted?
89
- g.feature = Flipper::ActiveRecord::Feature.select(:id).find_or_create_by!(name: feature.key)
90
- end
91
- g.save!
92
- when :set
93
- g = Flipper::ActiveRecord::Gate.joins(:feature).
94
- where(flipper_features: {name: feature.key}).
95
- find_or_initialize_by({
96
- name: gate.key.to_s,
97
- value: thing.value.to_s,
98
- })
99
- unless g.persisted?
100
- g.feature = Flipper::ActiveRecord::Feature.select(:id).find_or_create_by!(name: feature.key)
101
- end
102
- g.save!
103
- else
104
- unsupported_data_type gate.data_type
105
- end
106
-
107
- true
108
- end
109
-
110
- # Public: Disables a gate for a given thing.
111
- #
112
- # feature - The Flipper::Feature for the gate.
113
- # gate - The Flipper::Gate to disable.
114
- # thing - The Flipper::Type being disabled for the gate.
115
- #
116
- # Returns true.
117
- def disable(feature, gate, thing)
118
- scope = Flipper::ActiveRecord::Gate.joins(:feature).where(flipper_features: {name: feature.key})
119
-
120
- g = case gate.data_type
121
- when :boolean
122
- scope.destroy_all
123
- when :integer
124
- scope.where(name: gate.key.to_s).limit(1).
125
- update_all(value: thing.value.to_s)
126
- when :set
127
- scope.where(name: gate.key.to_s, value: thing.value.to_s).destroy_all
128
- else
129
- unsupported_data_type gate.data_type
130
- end
131
-
132
- true
133
- end
134
-
135
- # Private
136
- def unsupported_data_type(data_type)
137
- raise "#{data_type} is not supported by this adapter"
138
- end
139
-
140
- end
141
- end
142
- end
@@ -1,21 +0,0 @@
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
@@ -1,24 +0,0 @@
1
- class CreateFlipperTables < ActiveRecord::Migration
2
- def self.up
3
- create_table :flipper_features do |t|
4
- t.string :name, null: false
5
- t.timestamps null: false
6
- end
7
- add_index :flipper_features, :name, unique: true
8
-
9
- create_table :flipper_gates do |t|
10
- t.integer :flipper_feature_id, null: false
11
- t.string :name, null: false
12
- t.string :value
13
- t.timestamps null: false
14
- end
15
- add_foreign_key :flipper_gates, :flipper_features, on_delete: :cascade
16
- add_index :flipper_gates, [:flipper_feature_id, :name, :value], unique: true
17
- end
18
-
19
- def self.down
20
- remove_foreign_key :flipper_gates, :flipper_features
21
- drop_table :flipper_gates
22
- drop_table :flipper_features
23
- end
24
- end
@@ -1,9 +0,0 @@
1
- require 'helper'
2
- require 'flipper/adapters/activerecord'
3
- require 'flipper/spec/shared_adapter_specs'
4
-
5
- describe Flipper::Adapters::ActiveRecord do
6
- subject { described_class.new }
7
-
8
- it_should_behave_like 'a flipper adapter'
9
- end
data/spec/database.yml DELETED
@@ -1,3 +0,0 @@
1
- postgresql:
2
- adapter: postgresql
3
- database: flipper_activerecord_test
data/spec/helper.rb DELETED
@@ -1,56 +0,0 @@
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