setler 0.0.13 → 0.0.15

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.
@@ -0,0 +1,320 @@
1
+ GIT
2
+ remote: https://github.com/rails/rails
3
+ revision: f73b7f173b3004ec9e920b99dafaaf029887847a
4
+ specs:
5
+ actioncable (8.2.0.alpha)
6
+ actionpack (= 8.2.0.alpha)
7
+ activesupport (= 8.2.0.alpha)
8
+ nio4r (~> 2.0)
9
+ websocket-driver (>= 0.6.1)
10
+ zeitwerk (~> 2.6)
11
+ actionmailbox (8.2.0.alpha)
12
+ actionpack (= 8.2.0.alpha)
13
+ activejob (= 8.2.0.alpha)
14
+ activerecord (= 8.2.0.alpha)
15
+ activestorage (= 8.2.0.alpha)
16
+ activesupport (= 8.2.0.alpha)
17
+ mail (>= 2.8.0)
18
+ actionmailer (8.2.0.alpha)
19
+ actionpack (= 8.2.0.alpha)
20
+ actionview (= 8.2.0.alpha)
21
+ activejob (= 8.2.0.alpha)
22
+ activesupport (= 8.2.0.alpha)
23
+ mail (>= 2.8.0)
24
+ rails-dom-testing (~> 2.2)
25
+ actionpack (8.2.0.alpha)
26
+ actionview (= 8.2.0.alpha)
27
+ activesupport (= 8.2.0.alpha)
28
+ nokogiri (>= 1.8.5)
29
+ rack (>= 2.2.4)
30
+ rack-session (>= 1.0.1)
31
+ rack-test (>= 0.6.3)
32
+ rails-dom-testing (~> 2.2)
33
+ rails-html-sanitizer (~> 1.6)
34
+ useragent (~> 0.16)
35
+ actiontext (8.2.0.alpha)
36
+ action_text-trix (~> 2.1.15)
37
+ actionpack (= 8.2.0.alpha)
38
+ activerecord (= 8.2.0.alpha)
39
+ activestorage (= 8.2.0.alpha)
40
+ activesupport (= 8.2.0.alpha)
41
+ globalid (>= 0.6.0)
42
+ nokogiri (>= 1.8.5)
43
+ actionview (8.2.0.alpha)
44
+ activesupport (= 8.2.0.alpha)
45
+ builder (~> 3.1)
46
+ erubi (~> 1.11)
47
+ rails-dom-testing (~> 2.2)
48
+ rails-html-sanitizer (~> 1.6)
49
+ activejob (8.2.0.alpha)
50
+ activesupport (= 8.2.0.alpha)
51
+ globalid (>= 0.3.6)
52
+ activemodel (8.2.0.alpha)
53
+ activesupport (= 8.2.0.alpha)
54
+ activerecord (8.2.0.alpha)
55
+ activemodel (= 8.2.0.alpha)
56
+ activesupport (= 8.2.0.alpha)
57
+ timeout (>= 0.4.0)
58
+ activestorage (8.2.0.alpha)
59
+ actionpack (= 8.2.0.alpha)
60
+ activejob (= 8.2.0.alpha)
61
+ activerecord (= 8.2.0.alpha)
62
+ activesupport (= 8.2.0.alpha)
63
+ marcel (~> 1.0)
64
+ activesupport (8.2.0.alpha)
65
+ base64
66
+ bigdecimal
67
+ concurrent-ruby (~> 1.0, >= 1.3.1)
68
+ connection_pool (>= 2.2.5)
69
+ drb
70
+ i18n (>= 1.6, < 2)
71
+ json
72
+ logger (>= 1.4.2)
73
+ minitest (>= 5.1)
74
+ securerandom (>= 0.3)
75
+ tzinfo (~> 2.0, >= 2.0.5)
76
+ uri (>= 0.13.1)
77
+ rails (8.2.0.alpha)
78
+ actioncable (= 8.2.0.alpha)
79
+ actionmailbox (= 8.2.0.alpha)
80
+ actionmailer (= 8.2.0.alpha)
81
+ actionpack (= 8.2.0.alpha)
82
+ actiontext (= 8.2.0.alpha)
83
+ actionview (= 8.2.0.alpha)
84
+ activejob (= 8.2.0.alpha)
85
+ activemodel (= 8.2.0.alpha)
86
+ activerecord (= 8.2.0.alpha)
87
+ activestorage (= 8.2.0.alpha)
88
+ activesupport (= 8.2.0.alpha)
89
+ bundler (>= 1.15.0)
90
+ railties (= 8.2.0.alpha)
91
+ railties (8.2.0.alpha)
92
+ actionpack (= 8.2.0.alpha)
93
+ activesupport (= 8.2.0.alpha)
94
+ irb (~> 1.13)
95
+ rackup (>= 1.0.0)
96
+ rake (>= 12.2)
97
+ thor (~> 1.0, >= 1.2.2)
98
+ tsort (>= 0.2)
99
+ zeitwerk (~> 2.6)
100
+
101
+ PATH
102
+ remote: ..
103
+ specs:
104
+ setler (0.0.15)
105
+ activerecord (>= 3.0.0)
106
+ rails (>= 3.0.0)
107
+
108
+ GEM
109
+ remote: https://rubygems.org/
110
+ specs:
111
+ action_text-trix (2.1.15)
112
+ railties
113
+ appraisal (2.5.0)
114
+ bundler
115
+ rake
116
+ thor (>= 0.14.0)
117
+ ast (2.4.3)
118
+ base64 (0.3.0)
119
+ bigdecimal (3.3.1)
120
+ brakeman (5.4.1)
121
+ builder (3.3.0)
122
+ concurrent-ruby (1.3.5)
123
+ connection_pool (2.5.4)
124
+ crass (1.0.6)
125
+ date (3.4.1)
126
+ docile (1.4.1)
127
+ drb (2.2.3)
128
+ erb (5.1.1)
129
+ erubi (1.13.1)
130
+ globalid (1.3.0)
131
+ activesupport (>= 6.1)
132
+ i18n (1.14.7)
133
+ concurrent-ruby (~> 1.0)
134
+ io-console (0.8.1)
135
+ irb (1.15.2)
136
+ pp (>= 0.6.0)
137
+ rdoc (>= 4.0.0)
138
+ reline (>= 0.4.2)
139
+ json (2.15.1)
140
+ language_server-protocol (3.17.0.5)
141
+ lint_roller (1.1.0)
142
+ logger (1.7.0)
143
+ loofah (2.24.1)
144
+ crass (~> 1.0.2)
145
+ nokogiri (>= 1.12.0)
146
+ mail (2.9.0)
147
+ logger
148
+ mini_mime (>= 0.1.1)
149
+ net-imap
150
+ net-pop
151
+ net-smtp
152
+ marcel (1.1.0)
153
+ mini_mime (1.1.5)
154
+ minitest (5.26.0)
155
+ net-imap (0.5.12)
156
+ date
157
+ net-protocol
158
+ net-pop (0.1.2)
159
+ net-protocol
160
+ net-protocol (0.2.2)
161
+ timeout
162
+ net-smtp (0.5.1)
163
+ net-protocol
164
+ nio4r (2.7.4)
165
+ nokogiri (1.18.10-aarch64-linux-gnu)
166
+ racc (~> 1.4)
167
+ nokogiri (1.18.10-aarch64-linux-musl)
168
+ racc (~> 1.4)
169
+ nokogiri (1.18.10-arm-linux-gnu)
170
+ racc (~> 1.4)
171
+ nokogiri (1.18.10-arm-linux-musl)
172
+ racc (~> 1.4)
173
+ nokogiri (1.18.10-arm64-darwin)
174
+ racc (~> 1.4)
175
+ nokogiri (1.18.10-x86_64-darwin)
176
+ racc (~> 1.4)
177
+ nokogiri (1.18.10-x86_64-linux-gnu)
178
+ racc (~> 1.4)
179
+ nokogiri (1.18.10-x86_64-linux-musl)
180
+ racc (~> 1.4)
181
+ panolint (0.1.6)
182
+ brakeman (>= 4.8, < 6.0)
183
+ rubocop (>= 0.83, < 2.0)
184
+ rubocop-performance (~> 1.5)
185
+ rubocop-rails (~> 2.5)
186
+ rubocop-rake (~> 0.5)
187
+ rubocop-rspec (~> 2.0)
188
+ parallel (1.27.0)
189
+ parser (3.3.10.0)
190
+ ast (~> 2.4.1)
191
+ racc
192
+ pp (0.6.3)
193
+ prettyprint
194
+ prettyprint (0.2.0)
195
+ prism (1.6.0)
196
+ psych (5.2.6)
197
+ date
198
+ stringio
199
+ racc (1.8.1)
200
+ rack (3.2.3)
201
+ rack-session (2.1.1)
202
+ base64 (>= 0.1.0)
203
+ rack (>= 3.0.0)
204
+ rack-test (2.2.0)
205
+ rack (>= 1.3)
206
+ rackup (2.2.1)
207
+ rack (>= 3)
208
+ rails-dom-testing (2.3.0)
209
+ activesupport (>= 5.0.0)
210
+ minitest
211
+ nokogiri (>= 1.6)
212
+ rails-html-sanitizer (1.6.2)
213
+ loofah (~> 2.21)
214
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
215
+ rainbow (3.1.1)
216
+ rake (13.3.0)
217
+ rdoc (6.15.0)
218
+ erb
219
+ psych (>= 4.0.0)
220
+ tsort
221
+ regexp_parser (2.11.3)
222
+ reline (0.6.2)
223
+ io-console (~> 0.5)
224
+ rubocop (1.81.6)
225
+ json (~> 2.3)
226
+ language_server-protocol (~> 3.17.0.2)
227
+ lint_roller (~> 1.1.0)
228
+ parallel (~> 1.10)
229
+ parser (>= 3.3.0.2)
230
+ rainbow (>= 2.2.2, < 4.0)
231
+ regexp_parser (>= 2.9.3, < 3.0)
232
+ rubocop-ast (>= 1.47.1, < 2.0)
233
+ ruby-progressbar (~> 1.7)
234
+ unicode-display_width (>= 2.4.0, < 4.0)
235
+ rubocop-ast (1.47.1)
236
+ parser (>= 3.3.7.2)
237
+ prism (~> 1.4)
238
+ rubocop-capybara (2.22.1)
239
+ lint_roller (~> 1.1)
240
+ rubocop (~> 1.72, >= 1.72.1)
241
+ rubocop-factory_bot (2.27.1)
242
+ lint_roller (~> 1.1)
243
+ rubocop (~> 1.72, >= 1.72.1)
244
+ rubocop-performance (1.26.1)
245
+ lint_roller (~> 1.1)
246
+ rubocop (>= 1.75.0, < 2.0)
247
+ rubocop-ast (>= 1.47.1, < 2.0)
248
+ rubocop-rails (2.33.4)
249
+ activesupport (>= 4.2.0)
250
+ lint_roller (~> 1.1)
251
+ rack (>= 1.1)
252
+ rubocop (>= 1.75.0, < 2.0)
253
+ rubocop-ast (>= 1.44.0, < 2.0)
254
+ rubocop-rake (0.7.1)
255
+ lint_roller (~> 1.1)
256
+ rubocop (>= 1.72.1)
257
+ rubocop-rspec (2.31.0)
258
+ rubocop (~> 1.40)
259
+ rubocop-capybara (~> 2.17)
260
+ rubocop-factory_bot (~> 2.22)
261
+ rubocop-rspec_rails (~> 2.28)
262
+ rubocop-rspec_rails (2.29.1)
263
+ rubocop (~> 1.61)
264
+ ruby-progressbar (1.13.0)
265
+ securerandom (0.4.1)
266
+ simplecov (0.22.0)
267
+ docile (~> 1.1)
268
+ simplecov-html (~> 0.11)
269
+ simplecov_json_formatter (~> 0.1)
270
+ simplecov-html (0.13.2)
271
+ simplecov_json_formatter (0.1.4)
272
+ sqlite3 (2.7.4-aarch64-linux-gnu)
273
+ sqlite3 (2.7.4-aarch64-linux-musl)
274
+ sqlite3 (2.7.4-arm-linux-gnu)
275
+ sqlite3 (2.7.4-arm-linux-musl)
276
+ sqlite3 (2.7.4-arm64-darwin)
277
+ sqlite3 (2.7.4-x86_64-darwin)
278
+ sqlite3 (2.7.4-x86_64-linux-gnu)
279
+ sqlite3 (2.7.4-x86_64-linux-musl)
280
+ stringio (3.1.7)
281
+ thor (1.4.0)
282
+ timeout (0.4.3)
283
+ tsort (0.2.0)
284
+ tzinfo (2.0.6)
285
+ concurrent-ruby (~> 1.0)
286
+ unicode-display_width (3.2.0)
287
+ unicode-emoji (~> 4.1)
288
+ unicode-emoji (4.1.0)
289
+ uri (1.0.4)
290
+ useragent (0.16.11)
291
+ websocket-driver (0.8.0)
292
+ base64
293
+ websocket-extensions (>= 0.1.0)
294
+ websocket-extensions (0.1.5)
295
+ zeitwerk (2.7.3)
296
+
297
+ PLATFORMS
298
+ aarch64-linux-gnu
299
+ aarch64-linux-musl
300
+ arm-linux-gnu
301
+ arm-linux-musl
302
+ arm64-darwin
303
+ x86_64-darwin
304
+ x86_64-linux-gnu
305
+ x86_64-linux-musl
306
+
307
+ DEPENDENCIES
308
+ appraisal
309
+ minitest
310
+ panolint
311
+ rails!
312
+ rake
313
+ rubocop (~> 1.39)
314
+ rubocop-rake
315
+ setler!
316
+ simplecov
317
+ sqlite3
318
+
319
+ BUNDLED WITH
320
+ 2.6.9
@@ -9,6 +9,7 @@ class SetlerCreate<%= table_name.camelize %> < ActiveRecord::Migration
9
9
  end
10
10
 
11
11
  add_index :<%= table_name %>, [ :thing_type, :thing_id, :var ], unique: true
12
+ add_index :<%= table_name %>, :var, unique: true, where: "thing_id IS NULL AND thing_type is NULL"
12
13
  end
13
14
 
14
15
  def self.down
@@ -28,9 +28,9 @@ module Setler
28
28
  super(method, *args, &block)
29
29
  else
30
30
  method_name = method.to_s
31
- if method_name.ends_with?("=")
31
+ if method_name.end_with?("=")
32
32
  self[method_name[0..-2]] = args.first
33
- elsif method_name.ends_with?("?")
33
+ elsif method_name.end_with?("?")
34
34
  self[method_name[0..-2]].present?
35
35
  else
36
36
  self[method_name]
@@ -48,16 +48,24 @@ module Setler
48
48
  # thing_scoped.find_or_create_by_var(method_name[0..-2]) should work but doesnt for some reason
49
49
  # When @object is present, thing_scoped sets the where scope for the polymorphic association
50
50
  # but the find_or_create_by wasn't using the thing_type and thing_id
51
- thing_scoped.find_or_create_by(
52
- var: var.to_s,
53
- thing_type: @object.try(:class).try(:base_class).try(:to_s),
54
- thing_id: @object.try(:id)
55
- ).update_attributes({ :value => value })
51
+ if Rails::VERSION::MAJOR == 3
52
+ thing_scoped.find_or_create_by_var_and_thing_type_and_thing_id(
53
+ var.to_s,
54
+ @object.try(:class).try(:base_class).try(:to_s),
55
+ @object.try(:id)
56
+ ).update({ :value => value })
57
+ else
58
+ thing_scoped.find_or_create_by(
59
+ var: var.to_s,
60
+ thing_type: @object.try(:class).try(:base_class).try(:to_s),
61
+ thing_id: @object.try(:id)
62
+ ).update({ :value => value })
63
+ end
56
64
  end
57
65
 
58
66
  def self.destroy(var_name)
59
67
  var_name = var_name.to_s
60
- if setting = self.find_by_var(var_name)
68
+ if (setting = self.find_by_var(var_name))
61
69
  setting.destroy
62
70
  true
63
71
  else
@@ -1,3 +1,3 @@
1
1
  module Setler
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.15"
3
3
  end
data/setler.gemspec CHANGED
@@ -7,21 +7,38 @@ Gem::Specification.new do |s|
7
7
  s.version = Setler::VERSION
8
8
  s.authors = ["Chris Kelly"]
9
9
  s.email = ["ckdake@ckdake.com"]
10
+ s.license = 'MIT'
10
11
  s.homepage = "https://github.com/ckdake/setler"
11
12
  s.summary = %q{Settler lets you use the 'Feature Flags' pettern or add settings to models.}
12
13
  s.description = %q{Setler is a Gem that lets one easily implement the "Feature Flags" pattern, or add settings to individual models. This is a cleanroom implementation of what the 'rails-settings' gem does. It's been forked all over the place, and my favorite version of it doesn't have any tests and doesn't work with settings associated with models.}
13
14
 
14
- s.rubyforge_project = "setler"
15
-
16
15
  s.files = `git ls-files`.split("\n")
17
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
18
  s.require_paths = ["lib"]
20
19
 
20
+ supported_ruby_requirements = [
21
+ Gem::Requirement.new(["~> 2.6", ">= 2.6.10"]),
22
+ Gem::Requirement.new(["~> 2.7", ">= 2.7.8"]),
23
+ Gem::Requirement.new("~> 3.0"),
24
+ Gem::Requirement.new("~> 3.1"),
25
+ Gem::Requirement.new("~> 3.2"),
26
+ Gem::Requirement.new("~> 3.3"),
27
+ Gem::Requirement.new("~> 3.4"),
28
+ Gem::Requirement.new([">= 3.5.0.pre", "< 3.6"])
29
+ ].freeze
30
+
31
+ s.metadata['supported_ruby_requirements'] = supported_ruby_requirements.map(&:to_s).join(', ')
32
+ s.required_ruby_version = Gem::Requirement.new([">= 2.6.10"])
33
+
21
34
  s.add_dependency('activerecord', '>=3.0.0')
22
35
  s.add_dependency('rails', '>=3.0.0')
23
36
 
24
- s.add_development_dependency('sqlite3')
25
37
  s.add_development_dependency('rake')
26
38
  s.add_development_dependency('minitest')
39
+ s.add_development_dependency('simplecov')
40
+ s.add_development_dependency('appraisal')
41
+ s.add_development_dependency('rubocop', '~> 1.39')
42
+ s.add_development_dependency('rubocop-rake')
43
+ s.add_development_dependency('panolint')
27
44
  end
@@ -60,7 +60,7 @@ class ::SettingsTest < Minitest::Test
60
60
  def test_update_with_nil_and_default_not_nil
61
61
  ::Settings.defaults[:foo] = :test
62
62
  ::Settings.foo = nil
63
- assert_equal nil, ::Settings.foo
63
+ assert_nil ::Settings.foo
64
64
  end
65
65
 
66
66
  def test_update_with_array_syntax
@@ -76,8 +76,20 @@ class ::SettingsTest < Minitest::Test
76
76
  assert_equal '123', ::Settings.onetwothree
77
77
  end
78
78
 
79
+ def test_multithreaded_create
80
+ s1 = Settings.new var: :conflict, value: 1
81
+ s2 = Settings.new var: :conflict, value: 2
82
+ s1.save!
83
+ exc = assert_raises ActiveRecord::RecordNotUnique, ActiveRecord::StatementInvalid do
84
+ s2.save!
85
+ end
86
+ unless exc.is_a?(ActiveRecord::RecordNotUnique)
87
+ assert exc.message.match(/UNIQUE/)
88
+ end
89
+ end
90
+
79
91
  def test_complex_serialization
80
- complex = [1, '2', {:three => true}]
92
+ complex = [1, '2', {"three" => true}]
81
93
  ::Settings.complex = complex
82
94
  assert_equal complex, ::Settings.complex
83
95
  end
@@ -167,7 +179,7 @@ class ::SettingsTest < Minitest::Test
167
179
  ::Preferences.create var: 'test', value: 'preferences foo'
168
180
  ::Preferences.create var: 'test2', value: 'preferences bar'
169
181
 
170
- refute_match ::Settings.all_settings, ::Preferences.all_settings
182
+ refute_equal ::Settings.all_settings, ::Preferences.all_settings
171
183
 
172
184
  assert_equal 'foo', ::Settings[:test]
173
185
  assert_equal 'bar', ::Settings[:test2]
data/test/test_helper.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require 'rubygems'
2
2
 
3
+ require 'simplecov'
4
+ SimpleCov.start 'rails'
5
+
3
6
  require 'bundler'
4
7
  begin
5
8
  Bundler.setup(:default, :development)
@@ -34,18 +37,20 @@ def setup_db
34
37
  t.text :value, :null => true
35
38
  t.integer :thing_id, :null => true
36
39
  t.string :thing_type, :limit => 30, :null => true
37
- t.timestamps
40
+ t.timestamps null: false
38
41
  end
39
42
  add_index :settings, [ :thing_type, :thing_id, :var ], :unique => true
43
+ add_index :settings, :var, unique: true, where: "thing_id IS NULL AND thing_type is NULL"
40
44
 
41
45
  create_table :preferences do |t|
42
46
  t.string :var, :null => false
43
47
  t.text :value, :null => true
44
48
  t.integer :thing_id, :null => true
45
49
  t.string :thing_type, :limit => 30, :null => true
46
- t.timestamps
50
+ t.timestamps null: false
47
51
  end
48
52
  add_index :preferences, [ :thing_type, :thing_id, :var ], :unique => true
53
+ add_index :preferences, :var, unique: true, where: "thing_id IS NULL AND thing_type is NULL"
49
54
 
50
55
  create_table :users do |t|
51
56
  t.string :name