type_balancer_rails 0.2.2 → 0.2.3

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.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +4 -0
  3. data/.rubocop.yml +8 -23
  4. data/CHANGELOG.md +11 -3
  5. data/README.md +15 -0
  6. data/example/.dockerignore +51 -0
  7. data/example/.rspec +1 -0
  8. data/example/.rubocop.yml +132 -0
  9. data/example/Dockerfile +72 -0
  10. data/example/Gemfile +77 -0
  11. data/example/Gemfile.lock +449 -0
  12. data/example/README.md +42 -0
  13. data/example/Rakefile +6 -0
  14. data/example/app/assets/images/.keep +0 -0
  15. data/example/app/assets/stylesheets/application.css +10 -0
  16. data/example/app/controllers/application_controller.rb +4 -0
  17. data/example/app/controllers/concerns/.keep +0 -0
  18. data/example/app/controllers/contents_controller.rb +11 -0
  19. data/example/app/controllers/posts_controller.rb +5 -0
  20. data/example/app/helpers/application_helper.rb +2 -0
  21. data/example/app/helpers/contents_helper.rb +2 -0
  22. data/example/app/helpers/posts_helper.rb +2 -0
  23. data/example/app/jobs/application_job.rb +7 -0
  24. data/example/app/mailers/application_mailer.rb +4 -0
  25. data/example/app/models/application_record.rb +3 -0
  26. data/example/app/models/concerns/.keep +0 -0
  27. data/example/app/models/content.rb +3 -0
  28. data/example/app/models/post.rb +3 -0
  29. data/example/app/views/contents/balance_by_category.html.erb +27 -0
  30. data/example/app/views/contents/balance_by_content_type.html.erb +2 -0
  31. data/example/app/views/layouts/application.html.erb +27 -0
  32. data/example/app/views/layouts/mailer.html.erb +13 -0
  33. data/example/app/views/layouts/mailer.text.erb +1 -0
  34. data/example/app/views/posts/balance_by_category.html.erb +2 -0
  35. data/example/app/views/posts/index.html.erb +25 -0
  36. data/example/app/views/pwa/manifest.json.erb +22 -0
  37. data/example/app/views/pwa/service-worker.js +26 -0
  38. data/example/bin/brakeman +7 -0
  39. data/example/bin/dev +2 -0
  40. data/example/bin/docker-entrypoint +14 -0
  41. data/example/bin/rails +4 -0
  42. data/example/bin/rake +4 -0
  43. data/example/bin/rubocop +8 -0
  44. data/example/bin/setup +34 -0
  45. data/example/bin/thrust +5 -0
  46. data/example/config/application.rb +42 -0
  47. data/example/config/boot.rb +4 -0
  48. data/example/config/cable.yml +10 -0
  49. data/example/config/credentials.yml.enc +1 -0
  50. data/example/config/database.yml +41 -0
  51. data/example/config/environment.rb +5 -0
  52. data/example/config/environments/development.rb +72 -0
  53. data/example/config/environments/production.rb +89 -0
  54. data/example/config/environments/test.rb +53 -0
  55. data/example/config/initializers/assets.rb +7 -0
  56. data/example/config/initializers/content_security_policy.rb +25 -0
  57. data/example/config/initializers/filter_parameter_logging.rb +8 -0
  58. data/example/config/initializers/inflections.rb +16 -0
  59. data/example/config/locales/en.yml +31 -0
  60. data/example/config/master.key +1 -0
  61. data/example/config/puma.rb +41 -0
  62. data/example/config/routes.rb +8 -0
  63. data/example/config/storage.yml +34 -0
  64. data/example/config.ru +6 -0
  65. data/example/db/migrate/20250427174733_create_posts.rb +10 -0
  66. data/example/db/migrate/20250427174747_create_contents.rb +11 -0
  67. data/example/db/schema.rb +28 -0
  68. data/example/db/seeds.rb +9 -0
  69. data/example/lib/tasks/.keep +0 -0
  70. data/example/lib/tasks/dev_fixtures.rake +12 -0
  71. data/example/script/.keep +0 -0
  72. data/example/spec/controllers/contents_controller_spec.rb +27 -0
  73. data/example/spec/controllers/posts_controller_spec.rb +16 -0
  74. data/example/spec/features/contents_balancing_spec.rb +18 -0
  75. data/example/spec/features/posts_balancing_spec.rb +16 -0
  76. data/example/spec/models/content_spec.rb +19 -0
  77. data/example/spec/models/post_spec.rb +12 -0
  78. data/example/spec/rails_helper.rb +35 -0
  79. data/example/spec/spec_helper.rb +94 -0
  80. data/example/storage/.keep +0 -0
  81. data/example/storage/development.sqlite3 +0 -0
  82. data/example/storage/test.sqlite3 +0 -0
  83. data/example/test/fixtures/contents.yml +19 -0
  84. data/example/test/fixtures/posts.yml +16 -0
  85. data/example/vendor/.keep +0 -0
  86. data/lib/type_balancer/rails/collection_methods.rb +58 -33
  87. data/lib/type_balancer/rails/version.rb +1 -1
  88. data/type_balancer_rails.gemspec +1 -1
  89. metadata +85 -4
@@ -0,0 +1,449 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ type_balancer_rails (0.2.2)
5
+ activerecord (>= 7.0, < 9.0)
6
+ activesupport (>= 7.0, < 9.0)
7
+ type_balancer (~> 0.1, >= 0.1.4)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actioncable (8.0.2)
13
+ actionpack (= 8.0.2)
14
+ activesupport (= 8.0.2)
15
+ nio4r (~> 2.0)
16
+ websocket-driver (>= 0.6.1)
17
+ zeitwerk (~> 2.6)
18
+ actionmailbox (8.0.2)
19
+ actionpack (= 8.0.2)
20
+ activejob (= 8.0.2)
21
+ activerecord (= 8.0.2)
22
+ activestorage (= 8.0.2)
23
+ activesupport (= 8.0.2)
24
+ mail (>= 2.8.0)
25
+ actionmailer (8.0.2)
26
+ actionpack (= 8.0.2)
27
+ actionview (= 8.0.2)
28
+ activejob (= 8.0.2)
29
+ activesupport (= 8.0.2)
30
+ mail (>= 2.8.0)
31
+ rails-dom-testing (~> 2.2)
32
+ actionpack (8.0.2)
33
+ actionview (= 8.0.2)
34
+ activesupport (= 8.0.2)
35
+ nokogiri (>= 1.8.5)
36
+ rack (>= 2.2.4)
37
+ rack-session (>= 1.0.1)
38
+ rack-test (>= 0.6.3)
39
+ rails-dom-testing (~> 2.2)
40
+ rails-html-sanitizer (~> 1.6)
41
+ useragent (~> 0.16)
42
+ actiontext (8.0.2)
43
+ actionpack (= 8.0.2)
44
+ activerecord (= 8.0.2)
45
+ activestorage (= 8.0.2)
46
+ activesupport (= 8.0.2)
47
+ globalid (>= 0.6.0)
48
+ nokogiri (>= 1.8.5)
49
+ actionview (8.0.2)
50
+ activesupport (= 8.0.2)
51
+ builder (~> 3.1)
52
+ erubi (~> 1.11)
53
+ rails-dom-testing (~> 2.2)
54
+ rails-html-sanitizer (~> 1.6)
55
+ activejob (8.0.2)
56
+ activesupport (= 8.0.2)
57
+ globalid (>= 0.3.6)
58
+ activemodel (8.0.2)
59
+ activesupport (= 8.0.2)
60
+ activerecord (8.0.2)
61
+ activemodel (= 8.0.2)
62
+ activesupport (= 8.0.2)
63
+ timeout (>= 0.4.0)
64
+ activestorage (8.0.2)
65
+ actionpack (= 8.0.2)
66
+ activejob (= 8.0.2)
67
+ activerecord (= 8.0.2)
68
+ activesupport (= 8.0.2)
69
+ marcel (~> 1.0)
70
+ activesupport (8.0.2)
71
+ base64
72
+ benchmark (>= 0.3)
73
+ bigdecimal
74
+ concurrent-ruby (~> 1.0, >= 1.3.1)
75
+ connection_pool (>= 2.2.5)
76
+ drb
77
+ i18n (>= 1.6, < 2)
78
+ logger (>= 1.4.2)
79
+ minitest (>= 5.1)
80
+ securerandom (>= 0.3)
81
+ tzinfo (~> 2.0, >= 2.0.5)
82
+ uri (>= 0.13.1)
83
+ addressable (2.8.7)
84
+ public_suffix (>= 2.0.2, < 7.0)
85
+ ast (2.4.3)
86
+ base64 (0.2.0)
87
+ bcrypt_pbkdf (1.1.1)
88
+ bcrypt_pbkdf (1.1.1-arm64-darwin)
89
+ bcrypt_pbkdf (1.1.1-x86_64-darwin)
90
+ benchmark (0.4.0)
91
+ bigdecimal (3.1.9)
92
+ bindex (0.8.1)
93
+ bootsnap (1.18.4)
94
+ msgpack (~> 1.2)
95
+ brakeman (7.0.2)
96
+ racc
97
+ builder (3.3.0)
98
+ capybara (3.40.0)
99
+ addressable
100
+ matrix
101
+ mini_mime (>= 0.1.3)
102
+ nokogiri (~> 1.11)
103
+ rack (>= 1.6.0)
104
+ rack-test (>= 0.6.3)
105
+ regexp_parser (>= 1.5, < 3.0)
106
+ xpath (~> 3.2)
107
+ childprocess (5.1.0)
108
+ logger (~> 1.5)
109
+ coderay (1.1.3)
110
+ concurrent-ruby (1.3.5)
111
+ connection_pool (2.5.2)
112
+ crass (1.0.6)
113
+ database_cleaner-active_record (2.2.0)
114
+ activerecord (>= 5.a)
115
+ database_cleaner-core (~> 2.0.0)
116
+ database_cleaner-core (2.0.1)
117
+ date (3.4.1)
118
+ debug (1.10.0)
119
+ irb (~> 1.10)
120
+ reline (>= 0.3.8)
121
+ diff-lcs (1.6.1)
122
+ dotenv (3.1.8)
123
+ drb (2.2.1)
124
+ ed25519 (1.3.0)
125
+ erubi (1.13.1)
126
+ et-orbi (1.2.11)
127
+ tzinfo
128
+ fugit (1.11.1)
129
+ et-orbi (~> 1, >= 1.2.11)
130
+ raabro (~> 1.4)
131
+ globalid (1.2.1)
132
+ activesupport (>= 6.1)
133
+ i18n (1.14.7)
134
+ concurrent-ruby (~> 1.0)
135
+ importmap-rails (2.1.0)
136
+ actionpack (>= 6.0.0)
137
+ activesupport (>= 6.0.0)
138
+ railties (>= 6.0.0)
139
+ io-console (0.8.0)
140
+ irb (1.15.2)
141
+ pp (>= 0.6.0)
142
+ rdoc (>= 4.0.0)
143
+ reline (>= 0.4.2)
144
+ jbuilder (2.13.0)
145
+ actionview (>= 5.0.0)
146
+ activesupport (>= 5.0.0)
147
+ json (2.11.3)
148
+ kamal (2.5.3)
149
+ activesupport (>= 7.0)
150
+ base64 (~> 0.2)
151
+ bcrypt_pbkdf (~> 1.0)
152
+ concurrent-ruby (~> 1.2)
153
+ dotenv (~> 3.1)
154
+ ed25519 (~> 1.2)
155
+ net-ssh (~> 7.3)
156
+ sshkit (>= 1.23.0, < 2.0)
157
+ thor (~> 1.3)
158
+ zeitwerk (>= 2.6.18, < 3.0)
159
+ language_server-protocol (3.17.0.4)
160
+ launchy (3.1.1)
161
+ addressable (~> 2.8)
162
+ childprocess (~> 5.0)
163
+ logger (~> 1.6)
164
+ lint_roller (1.1.0)
165
+ logger (1.7.0)
166
+ loofah (2.24.0)
167
+ crass (~> 1.0.2)
168
+ nokogiri (>= 1.12.0)
169
+ mail (2.8.1)
170
+ mini_mime (>= 0.1.1)
171
+ net-imap
172
+ net-pop
173
+ net-smtp
174
+ marcel (1.0.4)
175
+ matrix (0.4.2)
176
+ method_source (1.1.0)
177
+ mini_mime (1.1.5)
178
+ minitest (5.25.5)
179
+ msgpack (1.8.0)
180
+ net-imap (0.5.7)
181
+ date
182
+ net-protocol
183
+ net-pop (0.1.2)
184
+ net-protocol
185
+ net-protocol (0.2.2)
186
+ timeout
187
+ net-scp (4.1.0)
188
+ net-ssh (>= 2.6.5, < 8.0.0)
189
+ net-sftp (4.0.0)
190
+ net-ssh (>= 5.0.0, < 8.0.0)
191
+ net-smtp (0.5.1)
192
+ net-protocol
193
+ net-ssh (7.3.0)
194
+ nio4r (2.7.4)
195
+ nokogiri (1.18.8-aarch64-linux-gnu)
196
+ racc (~> 1.4)
197
+ nokogiri (1.18.8-aarch64-linux-musl)
198
+ racc (~> 1.4)
199
+ nokogiri (1.18.8-arm-linux-gnu)
200
+ racc (~> 1.4)
201
+ nokogiri (1.18.8-arm-linux-musl)
202
+ racc (~> 1.4)
203
+ nokogiri (1.18.8-arm64-darwin)
204
+ racc (~> 1.4)
205
+ nokogiri (1.18.8-x86_64-darwin)
206
+ racc (~> 1.4)
207
+ nokogiri (1.18.8-x86_64-linux-gnu)
208
+ racc (~> 1.4)
209
+ nokogiri (1.18.8-x86_64-linux-musl)
210
+ racc (~> 1.4)
211
+ ostruct (0.6.1)
212
+ parallel (1.27.0)
213
+ parser (3.3.8.0)
214
+ ast (~> 2.4.1)
215
+ racc
216
+ pp (0.6.2)
217
+ prettyprint
218
+ prettyprint (0.2.0)
219
+ prism (1.4.0)
220
+ propshaft (1.1.0)
221
+ actionpack (>= 7.0.0)
222
+ activesupport (>= 7.0.0)
223
+ rack
224
+ railties (>= 7.0.0)
225
+ pry (0.15.2)
226
+ coderay (~> 1.1)
227
+ method_source (~> 1.0)
228
+ psych (5.2.3)
229
+ date
230
+ stringio
231
+ public_suffix (6.0.1)
232
+ puma (6.6.0)
233
+ nio4r (~> 2.0)
234
+ raabro (1.4.0)
235
+ racc (1.8.1)
236
+ rack (3.1.13)
237
+ rack-session (2.1.0)
238
+ base64 (>= 0.1.0)
239
+ rack (>= 3.0.0)
240
+ rack-test (2.2.0)
241
+ rack (>= 1.3)
242
+ rackup (2.2.1)
243
+ rack (>= 3)
244
+ rails (8.0.2)
245
+ actioncable (= 8.0.2)
246
+ actionmailbox (= 8.0.2)
247
+ actionmailer (= 8.0.2)
248
+ actionpack (= 8.0.2)
249
+ actiontext (= 8.0.2)
250
+ actionview (= 8.0.2)
251
+ activejob (= 8.0.2)
252
+ activemodel (= 8.0.2)
253
+ activerecord (= 8.0.2)
254
+ activestorage (= 8.0.2)
255
+ activesupport (= 8.0.2)
256
+ bundler (>= 1.15.0)
257
+ railties (= 8.0.2)
258
+ rails-controller-testing (1.0.5)
259
+ actionpack (>= 5.0.1.rc1)
260
+ actionview (>= 5.0.1.rc1)
261
+ activesupport (>= 5.0.1.rc1)
262
+ rails-dom-testing (2.2.0)
263
+ activesupport (>= 5.0.0)
264
+ minitest
265
+ nokogiri (>= 1.6)
266
+ rails-html-sanitizer (1.6.2)
267
+ loofah (~> 2.21)
268
+ 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)
269
+ railties (8.0.2)
270
+ actionpack (= 8.0.2)
271
+ activesupport (= 8.0.2)
272
+ irb (~> 1.13)
273
+ rackup (>= 1.0.0)
274
+ rake (>= 12.2)
275
+ thor (~> 1.0, >= 1.2.2)
276
+ zeitwerk (~> 2.6)
277
+ rainbow (3.1.1)
278
+ rake (13.2.1)
279
+ rdoc (6.13.1)
280
+ psych (>= 4.0.0)
281
+ regexp_parser (2.10.0)
282
+ reline (0.6.1)
283
+ io-console (~> 0.5)
284
+ rspec-core (3.13.3)
285
+ rspec-support (~> 3.13.0)
286
+ rspec-expectations (3.13.3)
287
+ diff-lcs (>= 1.2.0, < 2.0)
288
+ rspec-support (~> 3.13.0)
289
+ rspec-mocks (3.13.2)
290
+ diff-lcs (>= 1.2.0, < 2.0)
291
+ rspec-support (~> 3.13.0)
292
+ rspec-rails (7.1.1)
293
+ actionpack (>= 7.0)
294
+ activesupport (>= 7.0)
295
+ railties (>= 7.0)
296
+ rspec-core (~> 3.13)
297
+ rspec-expectations (~> 3.13)
298
+ rspec-mocks (~> 3.13)
299
+ rspec-support (~> 3.13)
300
+ rspec-support (3.13.2)
301
+ rubocop (1.75.3)
302
+ json (~> 2.3)
303
+ language_server-protocol (~> 3.17.0.2)
304
+ lint_roller (~> 1.1.0)
305
+ parallel (~> 1.10)
306
+ parser (>= 3.3.0.2)
307
+ rainbow (>= 2.2.2, < 4.0)
308
+ regexp_parser (>= 2.9.3, < 3.0)
309
+ rubocop-ast (>= 1.44.0, < 2.0)
310
+ ruby-progressbar (~> 1.7)
311
+ unicode-display_width (>= 2.4.0, < 4.0)
312
+ rubocop-ast (1.44.1)
313
+ parser (>= 3.3.7.2)
314
+ prism (~> 1.4)
315
+ rubocop-capybara (2.22.1)
316
+ lint_roller (~> 1.1)
317
+ rubocop (~> 1.72, >= 1.72.1)
318
+ rubocop-factory_bot (2.27.1)
319
+ lint_roller (~> 1.1)
320
+ rubocop (~> 1.72, >= 1.72.1)
321
+ rubocop-performance (1.25.0)
322
+ lint_roller (~> 1.1)
323
+ rubocop (>= 1.75.0, < 2.0)
324
+ rubocop-ast (>= 1.38.0, < 2.0)
325
+ rubocop-rails (2.31.0)
326
+ activesupport (>= 4.2.0)
327
+ lint_roller (~> 1.1)
328
+ rack (>= 1.1)
329
+ rubocop (>= 1.75.0, < 2.0)
330
+ rubocop-ast (>= 1.38.0, < 2.0)
331
+ rubocop-rails-omakase (1.1.0)
332
+ rubocop (>= 1.72)
333
+ rubocop-performance (>= 1.24)
334
+ rubocop-rails (>= 2.30)
335
+ rubocop-rspec (3.6.0)
336
+ lint_roller (~> 1.1)
337
+ rubocop (~> 1.72, >= 1.72.1)
338
+ ruby-progressbar (1.13.0)
339
+ securerandom (0.4.1)
340
+ solid_cable (3.0.7)
341
+ actioncable (>= 7.2)
342
+ activejob (>= 7.2)
343
+ activerecord (>= 7.2)
344
+ railties (>= 7.2)
345
+ solid_cache (1.0.7)
346
+ activejob (>= 7.2)
347
+ activerecord (>= 7.2)
348
+ railties (>= 7.2)
349
+ solid_queue (1.1.5)
350
+ activejob (>= 7.1)
351
+ activerecord (>= 7.1)
352
+ concurrent-ruby (>= 1.3.1)
353
+ fugit (~> 1.11.0)
354
+ railties (>= 7.1)
355
+ thor (~> 1.3.1)
356
+ sqlite3 (2.6.0-aarch64-linux-gnu)
357
+ sqlite3 (2.6.0-aarch64-linux-musl)
358
+ sqlite3 (2.6.0-arm-linux-gnu)
359
+ sqlite3 (2.6.0-arm-linux-musl)
360
+ sqlite3 (2.6.0-arm64-darwin)
361
+ sqlite3 (2.6.0-x86_64-darwin)
362
+ sqlite3 (2.6.0-x86_64-linux-gnu)
363
+ sqlite3 (2.6.0-x86_64-linux-musl)
364
+ sshkit (1.24.0)
365
+ base64
366
+ logger
367
+ net-scp (>= 1.1.2)
368
+ net-sftp (>= 2.1.2)
369
+ net-ssh (>= 2.8.0)
370
+ ostruct
371
+ stimulus-rails (1.3.4)
372
+ railties (>= 6.0.0)
373
+ stringio (3.1.7)
374
+ thor (1.3.2)
375
+ thruster (0.1.13)
376
+ thruster (0.1.13-aarch64-linux)
377
+ thruster (0.1.13-arm64-darwin)
378
+ thruster (0.1.13-x86_64-darwin)
379
+ thruster (0.1.13-x86_64-linux)
380
+ timeout (0.4.3)
381
+ turbo-rails (2.0.13)
382
+ actionpack (>= 7.1.0)
383
+ railties (>= 7.1.0)
384
+ type_balancer (0.1.4)
385
+ tzinfo (2.0.6)
386
+ concurrent-ruby (~> 1.0)
387
+ unicode-display_width (3.1.4)
388
+ unicode-emoji (~> 4.0, >= 4.0.4)
389
+ unicode-emoji (4.0.4)
390
+ uri (1.0.3)
391
+ useragent (0.16.11)
392
+ web-console (4.2.1)
393
+ actionview (>= 6.0.0)
394
+ activemodel (>= 6.0.0)
395
+ bindex (>= 0.4.0)
396
+ railties (>= 6.0.0)
397
+ websocket-driver (0.7.7)
398
+ base64
399
+ websocket-extensions (>= 0.1.0)
400
+ websocket-extensions (0.1.5)
401
+ xpath (3.2.0)
402
+ nokogiri (~> 1.8)
403
+ zeitwerk (2.7.2)
404
+
405
+ PLATFORMS
406
+ aarch64-linux
407
+ aarch64-linux-gnu
408
+ aarch64-linux-musl
409
+ arm-linux-gnu
410
+ arm-linux-musl
411
+ arm64-darwin
412
+ x86_64-darwin
413
+ x86_64-linux
414
+ x86_64-linux-gnu
415
+ x86_64-linux-musl
416
+
417
+ DEPENDENCIES
418
+ bootsnap
419
+ brakeman
420
+ capybara
421
+ database_cleaner-active_record (~> 2.2)
422
+ debug
423
+ importmap-rails
424
+ jbuilder
425
+ kamal
426
+ launchy
427
+ propshaft
428
+ pry
429
+ puma (>= 5.0)
430
+ rails (~> 8.0.2)
431
+ rails-controller-testing
432
+ rspec-rails (~> 7.1)
433
+ rubocop-capybara (~> 2.22)
434
+ rubocop-factory_bot (~> 2.27)
435
+ rubocop-rails-omakase
436
+ rubocop-rspec (~> 3.6)
437
+ solid_cable
438
+ solid_cache
439
+ solid_queue
440
+ sqlite3 (>= 2.1)
441
+ stimulus-rails
442
+ thruster
443
+ turbo-rails
444
+ type_balancer_rails!
445
+ tzinfo-data
446
+ web-console
447
+
448
+ BUNDLED WITH
449
+ 2.6.2
data/example/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+ # Example App for type_balancer_rails
27
+
28
+ ## Idiomatic Usage
29
+
30
+ The preferred way to configure type balancing in your Rails models is:
31
+
32
+ ```ruby
33
+ class Post < ApplicationRecord
34
+ balance_by_type :media_type
35
+ end
36
+ ```
37
+
38
+ This is the most Rails-like and concise way to set the type field for balancing. The hash form (`balance_by_type type_field: :media_type`) is also supported for advanced options, but the above is recommended for most cases.
39
+
40
+ ---
41
+
42
+ (Continue with other documentation as needed)
data/example/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative "config/application"
5
+
6
+ Rails.application.load_tasks
File without changes
@@ -0,0 +1,10 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css.
3
+ *
4
+ * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
5
+ * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
6
+ * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
7
+ * depending on specificity.
8
+ *
9
+ * Consider organizing styles into separate files for maintainability.
10
+ */
@@ -0,0 +1,4 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
3
+ allow_browser versions: :modern
4
+ end
File without changes
@@ -0,0 +1,11 @@
1
+ class ContentsController < ApplicationController
2
+ def balance_by_category
3
+ @contents = Content.all.balance_by_type(type_field: :category)
4
+ render :balance_by_category
5
+ end
6
+
7
+ def balance_by_content_type
8
+ @contents = Content.all.balance_by_type(type_field: :content_type)
9
+ render :balance_by_content_type
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ class PostsController < ApplicationController
2
+ def index
3
+ @posts = Post.all.balance_by_type
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module ContentsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module PostsHelper
2
+ end
@@ -0,0 +1,7 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ # Automatically retry jobs that encountered a deadlock
3
+ # retry_on ActiveRecord::Deadlocked
4
+
5
+ # Most jobs are safe to ignore if the underlying records are no longer available
6
+ # discard_on ActiveJob::DeserializationError
7
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: "from@example.com"
3
+ layout "mailer"
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ primary_abstract_class
3
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ class Content < ApplicationRecord
2
+ # No default type_field; specify per call in controller actions
3
+ end
@@ -0,0 +1,3 @@
1
+ class Post < ApplicationRecord
2
+ balance_by_type type_field: :media_type
3
+ end
@@ -0,0 +1,27 @@
1
+ <h1>Contents (Balanced by <%= params[:action] == 'balance_by_category' ? ':category' : ':content_type' %>)</h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <th>Title</th>
7
+ <th>Category</th>
8
+ <th>Content Type</th>
9
+ </tr>
10
+ </thead>
11
+ <tbody>
12
+ <% @contents.each do |content| %>
13
+ <tr>
14
+ <td><%= content.title %></td>
15
+ <td><%= content.category %></td>
16
+ <td><%= content.content_type %></td>
17
+ </tr>
18
+ <% end %>
19
+ </tbody>
20
+ </table>
21
+
22
+ <hr>
23
+ <ul>
24
+ <li><%= link_to 'Back to Posts', posts_path %></li>
25
+ <li><%= link_to 'Balance by Category', balance_contents_by_category_path %></li>
26
+ <li><%= link_to 'Balance by Content Type', balance_contents_by_content_type_path %></li>
27
+ </ul>
@@ -0,0 +1,2 @@
1
+ <h1>Contents#balance_by_content_type</h1>
2
+ <p>Find me in app/views/contents/balance_by_content_type.html.erb</p>
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= content_for(:title) || "Example" %></title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <meta name="apple-mobile-web-app-capable" content="yes">
7
+ <meta name="mobile-web-app-capable" content="yes">
8
+ <%= csrf_meta_tags %>
9
+ <%= csp_meta_tag %>
10
+
11
+ <%= yield :head %>
12
+
13
+ <%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %>
14
+ <%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %>
15
+
16
+ <link rel="icon" href="/icon.png" type="image/png">
17
+ <link rel="icon" href="/icon.svg" type="image/svg+xml">
18
+ <link rel="apple-touch-icon" href="/icon.png">
19
+
20
+ <%# Includes all stylesheet files in app/assets/stylesheets %>
21
+ <%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
22
+ </head>
23
+
24
+ <body>
25
+ <%= yield %>
26
+ </body>
27
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,2 @@
1
+ <h1>Posts#balance_by_category</h1>
2
+ <p>Find me in app/views/posts/balance_by_category.html.erb</p>
@@ -0,0 +1,25 @@
1
+ <h1>Posts (Balanced by :media_type)</h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <th>Title</th>
7
+ <th>Media Type</th>
8
+ </tr>
9
+ </thead>
10
+ <tbody>
11
+ <% @posts.each do |post| %>
12
+ <tr>
13
+ <td><%= post.title %></td>
14
+ <td><%= post.media_type %></td>
15
+ </tr>
16
+ <% end %>
17
+ </tbody>
18
+ </table>
19
+
20
+ <hr>
21
+ <h2>Try Content Balancing Examples:</h2>
22
+ <ul>
23
+ <li><%= link_to 'Balance Contents by Category', balance_contents_by_category_path %></li>
24
+ <li><%= link_to 'Balance Contents by Content Type', balance_contents_by_content_type_path %></li>
25
+ </ul>