b4um_generators 0.4.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15fb9392677d61fa44d0d18bfa6fa71f8cde33202c1d3ab846eeded8cc255240
4
- data.tar.gz: 07256f3c068de795270adf8e1376f155f657c6a13b4d356ce414a289c6456be2
3
+ metadata.gz: c28062a0ee906885d252d4f10519103efd322fb0b4543f4e2c50583e806cb8eb
4
+ data.tar.gz: 914c0f060ab2e9f27ab11441f66c822696c7d2c928038880fb2c31f2c6113546
5
5
  SHA512:
6
- metadata.gz: c2c4efca4c04e8e8ef528e246d16c2e536c1b54e6dd356c284e96659664756edeacdfcb93d135cbebdf39ace19f869c5ca49dafbfe5ad9867c3703c92228bb8b
7
- data.tar.gz: af333b2df50d0530cfbf701b3fa040a80ba5d716cae4a67909be39d1f59d5c1bad6795b9a39691284e6cce2e867ed512ec7cf047f72bdff579db3741e8349ee6
6
+ metadata.gz: 8f0e80c477c65da9362ea6bff1c23760d620a639e40cda8ab3070ff2e6389dd70cb305bce39ea837259a1ed5d5ca33273217f87f8037d607d3774b9d60ffa155
7
+ data.tar.gz: b94e7e85275276d551a090797bf08bccaabfe90e89ab9ed10d9b2208a1e092605eb563411fd79700b8a0e5bbf1e4042d093c3688cd9d160733daa5cf54a0b5e2
data/.rubocop.yml CHANGED
@@ -15,14 +15,14 @@ Style/StringLiteralsInInterpolation:
15
15
  EnforcedStyle: double_quotes
16
16
 
17
17
  Metrics/MethodLength:
18
- Max: 1050
18
+ Max: 1200
19
19
 
20
20
  Metrics/BlockLength:
21
21
  Exclude:
22
22
  - 'spec/**/*'
23
23
 
24
24
  Metrics/ClassLength:
25
- Max: 1050
25
+ Max: 1200
26
26
 
27
27
  Metrics/AbcSize:
28
28
  Max: 100
data/CHANGELOG.md CHANGED
@@ -4,6 +4,48 @@ All notable changes to b4um Generators will be documented in this file.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.4.2] - 2026-10-13
8
+
9
+ ### Fixed
10
+
11
+ - Fixed indentation of generated `to_param` methods in the Readable generator
12
+ - Fixed `--param` formatting in generated scaffold models
13
+ - Fixed scaffold revoke behavior so generated model, controller and navigation changes are removed cleanly
14
+ - Fixed scaffold navigation cleanup during revoke
15
+ - Fixed Sortable migration detection when another database table already contains a `position` column
16
+ - Fixed Sortable model formatting when adding position callbacks
17
+ - Fixed Sortable fixture generation for `NOT NULL` position columns
18
+ - Fixed partially positioned Sortable fixtures while preserving fixture metadata
19
+ - Fixed Comments routing when the target resource already uses a block
20
+ - Fixed Authentication helper formatting in `ApplicationController`
21
+ - Fixed Admin helper and blocked-session formatting
22
+ - Fixed Admin revoke handling for generated authentication and route changes
23
+ - Fixed In-Place generator integration and formatting edge cases
24
+
25
+ ### Changed
26
+
27
+ - Improved generator idempotency and revoke behavior
28
+ - Improved integration between Scaffold, Authentication, Admin, Comments, Sortable and In-Place generators
29
+ - Expanded regression coverage for generator formatting, routing, fixtures and revoke behavior
30
+ - Increased RuboCop line-length configuration for the generator source
31
+ - Verified the complete generator suite with 466 RSpec examples and 0 failures
32
+ - Verified generated applications with Rails 8.1.4
33
+
34
+ ## [0.4.1] - 2026-10-13
35
+
36
+ ### Fixed
37
+
38
+ - Fixed scaffold password tests for bcrypt-backed authentication
39
+ - Fixed generated destroy formatting
40
+ - Fixed generated fixtures for authentication models with unique email addresses
41
+ - Fixed generated authentication tests for protected actions
42
+
43
+ ### Changed
44
+
45
+ - Improved Authentication integration with generated scaffold tests
46
+ - Improved generated test setup for authenticated resources
47
+ - Improved bcrypt integration in generated applications
48
+
7
49
  ## [0.4.0] - 2026-10-12
8
50
 
9
51
  ### Added
data/README.de.md CHANGED
@@ -24,7 +24,7 @@ b4um Generators wird während der Entwicklung derzeit als lokales Gem verwendet.
24
24
  Füge das Gem zur `Gemfile` der Rails-Anwendung hinzu:
25
25
 
26
26
  ```ruby
27
- gem "b4um_generators", "~> 0.4.0", path: "/pfad/zu/b4um_generators"
27
+ gem "b4um_generators", "~> 0.4.2", path: "/pfad/zu/b4um_generators"
28
28
  ```
29
29
 
30
30
  Führe anschließend aus:
@@ -1549,7 +1549,7 @@ wird.
1549
1549
 
1550
1550
  ## Version
1551
1551
 
1552
- Aktuelle Version: `0.4.0`
1552
+ Aktuelle Version: `0.4.2`
1553
1553
 
1554
1554
  ## Autor
1555
1555
 
data/README.md CHANGED
@@ -23,7 +23,7 @@ b4um Generators is currently used as a local gem during development.
23
23
  Add the gem to the Rails application's `Gemfile`:
24
24
 
25
25
  ```ruby
26
- gem "b4um_generators", "~> 0.4.0", path: "/path/to/b4um_generators"
26
+ gem "b4um_generators", "~> 0.4.2", path: "/path/to/b4um_generators"
27
27
  ```
28
28
 
29
29
  Then run:
@@ -1524,7 +1524,7 @@ The gem can be tested locally by referencing the repository with `path:` from a
1524
1524
 
1525
1525
  ## Version
1526
1526
 
1527
- Current version: `0.4.0`
1527
+ Current version: `0.4.2`
1528
1528
 
1529
1529
  ## Author
1530
1530
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module B4umGenerators
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.2"
5
5
  end
@@ -146,6 +146,27 @@ module B4um
146
146
 
147
147
  controller = File.read(full_controller_path)
148
148
 
149
+ require_admin = [
150
+ "",
151
+ " def require_admin",
152
+ " return if logged_in? && #{current_authentication_method}.admin?",
153
+ "",
154
+ ' redirect_to root_path, alert: "Access denied."',
155
+ " end",
156
+ ""
157
+ ].join("\n")
158
+
159
+ if behavior == :revoke
160
+ return unless controller.include?(require_admin)
161
+
162
+ File.write(
163
+ full_controller_path,
164
+ controller.sub(require_admin, "")
165
+ )
166
+
167
+ return
168
+ end
169
+
149
170
  return if controller.include?("def require_admin")
150
171
 
151
172
  class_end_position = controller.rindex(/^end\s*$/)
@@ -155,16 +176,6 @@ module B4um
155
176
  "Could not find the end of ApplicationController."
156
177
  end
157
178
 
158
- require_admin = <<~RUBY
159
-
160
- def require_admin
161
- return if logged_in? && #{current_authentication_method}.admin?
162
-
163
- redirect_to root_path, alert: "Access denied."
164
- end
165
-
166
- RUBY
167
-
168
179
  controller.insert(
169
180
  class_end_position,
170
181
  require_admin
@@ -227,6 +238,27 @@ module B4um
227
238
  "Routes not found: #{routes_path}"
228
239
  end
229
240
 
241
+ if behavior == :revoke
242
+ routes = File.read(full_routes_path)
243
+
244
+ routes.gsub!(
245
+ /^ #{Regexp.escape(admin_root_route)}\n?/,
246
+ ""
247
+ )
248
+
249
+ routes.gsub!(
250
+ /^#{Regexp.escape(indented_admin_users_route)}\n?/,
251
+ ""
252
+ )
253
+
254
+ File.write(
255
+ full_routes_path,
256
+ routes
257
+ )
258
+
259
+ return
260
+ end
261
+
230
262
  admin_users_route_status =
231
263
  upgrade_existing_admin_users_route(
232
264
  routes_path,
@@ -261,33 +293,77 @@ module B4um
261
293
 
262
294
  controller = File.read(full_controller_path)
263
295
 
264
- return if controller.include?("if @#{current_authentication_method}&.blocked?")
265
-
266
296
  current_user_assignment =
267
297
  "@#{current_authentication_method} ||= " \
268
298
  "#{authentication_class_name}.find_by(" \
269
299
  "id: session[:#{authentication_model_name}_id])"
270
300
 
271
- unless controller.include?(current_user_assignment)
301
+ blocked_session_block = [
302
+ current_user_assignment,
303
+ "",
304
+ "if @#{current_authentication_method}&.blocked?",
305
+ " session.delete(:#{authentication_model_name}_id)",
306
+ " @#{current_authentication_method} = nil",
307
+ "end",
308
+ "",
309
+ "@#{current_authentication_method}"
310
+ ]
311
+
312
+ if behavior == :revoke
313
+ blocked_pattern = /
314
+ ^(?<indent>[ \t]*)#{Regexp.escape(current_user_assignment)}\n
315
+ \n
316
+ ^\k<indent>if\ @#{Regexp.escape(current_authentication_method)}&\.blocked\?\n
317
+ ^\k<indent>\ \ session\.delete\(:#{Regexp.escape(authentication_model_name)}_id\)\n
318
+ ^\k<indent>\ \ @#{Regexp.escape(current_authentication_method)}\ =\ nil\n
319
+ ^\k<indent>end\n
320
+ \n
321
+ ^\k<indent>@#{Regexp.escape(current_authentication_method)}$
322
+ /x
323
+
324
+ match = controller.match(blocked_pattern)
325
+
326
+ return unless match
327
+
328
+ replacement =
329
+ "#{match[:indent]}#{current_user_assignment}"
330
+
331
+ File.write(
332
+ full_controller_path,
333
+ controller.sub(
334
+ blocked_pattern,
335
+ replacement
336
+ )
337
+ )
338
+
339
+ return
340
+ end
341
+
342
+ return if controller.include?(
343
+ "if @#{current_authentication_method}&.blocked?"
344
+ )
345
+
346
+ assignment_match = controller.match(
347
+ /^([ \t]*)#{Regexp.escape(current_user_assignment)}$/
348
+ )
349
+
350
+ unless assignment_match
272
351
  raise Thor::Error,
273
352
  "Could not find the current authentication method " \
274
353
  "in #{controller_path}"
275
354
  end
276
355
 
277
- replacement = <<~RUBY.chomp
278
- #{current_user_assignment}
356
+ indentation = assignment_match[1]
279
357
 
280
- if @#{current_authentication_method}&.blocked?
281
- session.delete(:#{authentication_model_name}_id)
282
- @#{current_authentication_method} = nil
283
- end
284
-
285
- @#{current_authentication_method}
286
- RUBY
358
+ replacement = blocked_session_block
359
+ .map do |line|
360
+ line.empty? ? line : "#{indentation}#{line}"
361
+ end
362
+ .join("\n")
287
363
 
288
364
  gsub_file(
289
365
  controller_path,
290
- current_user_assignment,
366
+ /^#{Regexp.escape(indentation)}#{Regexp.escape(current_user_assignment)}$/,
291
367
  replacement
292
368
  )
293
369
  end
@@ -307,14 +383,52 @@ module B4um
307
383
 
308
384
  controller = File.read(full_controller_path)
309
385
 
310
- return if controller.include?(
311
- "if #{authentication_model_name}.blocked?"
312
- )
313
-
314
386
  session_assignment =
315
387
  "session[:#{authentication_model_name}_id] = " \
316
388
  "#{authentication_model_name}.id"
317
389
 
390
+ login_redirect =
391
+ 'redirect_to root_path, notice: "Successfully logged in."'
392
+
393
+ if behavior == :revoke
394
+ blocked_login_pattern = /
395
+ ^(?<indent>[ \t]*)if\ #{Regexp.escape(authentication_model_name)}\.blocked\?\n
396
+ ^\k<indent>\ \ flash\.now\[:alert\]\ =\ "Account\ is\ blocked\."\n
397
+ ^\k<indent>\ \ render\ :new,\ status:\ :unprocessable_content\n
398
+ ^\k<indent>else\n
399
+ ^\k<indent>\ \ #{Regexp.escape(session_assignment)}\n
400
+ \n
401
+ ^\k<indent>\ \ #{Regexp.escape(login_redirect)}\n
402
+ ^\k<indent>end$
403
+ /x
404
+
405
+ match = controller.match(blocked_login_pattern)
406
+
407
+ return unless match
408
+
409
+ indentation = match[:indent]
410
+
411
+ replacement = [
412
+ "#{indentation}#{session_assignment}",
413
+ "",
414
+ "#{indentation}#{login_redirect}"
415
+ ].join("\n")
416
+
417
+ File.write(
418
+ full_controller_path,
419
+ controller.sub(
420
+ blocked_login_pattern,
421
+ replacement
422
+ )
423
+ )
424
+
425
+ return
426
+ end
427
+
428
+ return if controller.include?(
429
+ "if #{authentication_model_name}.blocked?"
430
+ )
431
+
318
432
  session_match = controller.match(
319
433
  /^(\s*)#{Regexp.escape(session_assignment)}$/
320
434
  )
@@ -342,9 +456,6 @@ module B4um
342
456
  replacement
343
457
  )
344
458
 
345
- login_redirect =
346
- 'redirect_to root_path, notice: "Successfully logged in."'
347
-
348
459
  controller = File.read(full_controller_path)
349
460
 
350
461
  redirect_match = controller.match(