b4um_generators 0.4.0 → 0.5.0

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: 32be49cb4a38e8c75eba464939aa99d73d45784f0434d3aa75f0b4d7fd57862f
4
+ data.tar.gz: a3af1d5dcb53dd3aa945f92f05ec84bdb271c0a6ffc14fb1c99c96232d7a6407
5
5
  SHA512:
6
- metadata.gz: c2c4efca4c04e8e8ef528e246d16c2e536c1b54e6dd356c284e96659664756edeacdfcb93d135cbebdf39ace19f869c5ca49dafbfe5ad9867c3703c92228bb8b
7
- data.tar.gz: af333b2df50d0530cfbf701b3fa040a80ba5d716cae4a67909be39d1f59d5c1bad6795b9a39691284e6cce2e867ed512ec7cf047f72bdff579db3741e8349ee6
6
+ metadata.gz: c00cf8cab52aa8f5edf31b01ac68e948c2f8019ba2978542546be8daa79a138c40673b421c82ba5933e51553b781fbd700fcac3857d973b3da13816904e20b90
7
+ data.tar.gz: d9b452a787712782c27a4a02799cac27b0ee2566bb97bb8e14875fe521e89a17eb2632873a5c772385e78264abf0204a3dba696b37c830e20d911c01ae17b220
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,75 @@ All notable changes to b4um Generators will be documented in this file.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.5.0] - 2026-10-14
8
+
9
+ ### Added
10
+
11
+ - Added complete Todo application generator with `b4um:todo`
12
+ - Added task creation, completion, reopening and deletion
13
+ - Added separate lists for open and completed tasks
14
+ - Added automatic task counters and progress tracking
15
+ - Added progress bar with completion percentage
16
+ - Added Turbo Stream updates without full page reloads
17
+ - Added Stimulus controller for task input handling
18
+ - Added automatic input reset after successful task creation
19
+ - Added responsive Todo layout with b4um cards and floating labels
20
+ - Added light and dark mode support for Todo components
21
+ - Added optional `--owner=MODEL` support for personal Todo lists
22
+ - Added integration with b4um authentication and current account helpers
23
+ - Added owner-specific task access protection
24
+ - Added HTTP 401 responses for unauthenticated owner-specific Todo requests
25
+ - Added 35 RSpec examples for the Todo generator
26
+
27
+ ### Changed
28
+
29
+ - Extended `b4um:help` with Todo generator documentation
30
+ - Extended Help generator RSpec coverage for Todo
31
+ - Updated English and German README documentation
32
+ - Updated the generator overview to include `b4um:todo`
33
+
34
+ ## [0.4.2] - 2026-10-13
35
+
36
+ ### Fixed
37
+
38
+ - Fixed indentation of generated `to_param` methods in the Readable generator
39
+ - Fixed `--param` formatting in generated scaffold models
40
+ - Fixed scaffold revoke behavior so generated model, controller and navigation changes are removed cleanly
41
+ - Fixed scaffold navigation cleanup during revoke
42
+ - Fixed Sortable migration detection when another database table already contains a `position` column
43
+ - Fixed Sortable model formatting when adding position callbacks
44
+ - Fixed Sortable fixture generation for `NOT NULL` position columns
45
+ - Fixed partially positioned Sortable fixtures while preserving fixture metadata
46
+ - Fixed Comments routing when the target resource already uses a block
47
+ - Fixed Authentication helper formatting in `ApplicationController`
48
+ - Fixed Admin helper and blocked-session formatting
49
+ - Fixed Admin revoke handling for generated authentication and route changes
50
+ - Fixed In-Place generator integration and formatting edge cases
51
+
52
+ ### Changed
53
+
54
+ - Improved generator idempotency and revoke behavior
55
+ - Improved integration between Scaffold, Authentication, Admin, Comments, Sortable and In-Place generators
56
+ - Expanded regression coverage for generator formatting, routing, fixtures and revoke behavior
57
+ - Increased RuboCop line-length configuration for the generator source
58
+ - Verified the complete generator suite with 466 RSpec examples and 0 failures
59
+ - Verified generated applications with Rails 8.1.4
60
+
61
+ ## [0.4.1] - 2026-10-13
62
+
63
+ ### Fixed
64
+
65
+ - Fixed scaffold password tests for bcrypt-backed authentication
66
+ - Fixed generated destroy formatting
67
+ - Fixed generated fixtures for authentication models with unique email addresses
68
+ - Fixed generated authentication tests for protected actions
69
+
70
+ ### Changed
71
+
72
+ - Improved Authentication integration with generated scaffold tests
73
+ - Improved generated test setup for authenticated resources
74
+ - Improved bcrypt integration in generated applications
75
+
7
76
  ## [0.4.0] - 2026-10-12
8
77
 
9
78
  ### Added
data/README.de.md CHANGED
@@ -6,8 +6,8 @@ b4um Generators ist eine Sammlung wiederverwendbarer Rails-Generatoren, Template
6
6
  für b4um-Rails-Projekte.
7
7
 
8
8
  Das Gem bietet eine einheitliche Grundlage für Rails-Anwendungen und enthält Generatoren für Scaffolds, Controller,
9
- Bento-Layouts, Tabellen, Pagination, Infinite Scroll, Suche, Kommentare, Authentifizierung, Administration, Gastzugänge,
10
- Attachments und Rich-Text-Bearbeitung.
9
+ Bento-Layouts, Tabellen, Pagination, Infinite Scroll, Suche, Sortierung, Todo-Listen, Kommentare, Authentifizierung,
10
+ Administration, Gastzugänge, Attachments und Rich-Text-Bearbeitung.
11
11
 
12
12
  Die generierten Komponenten verwenden ein gemeinsames b4um-Styling und sind darauf ausgelegt, miteinander zu
13
13
  funktionieren.
@@ -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.5.0", path: "/pfad/zu/b4um_generators"
28
28
  ```
29
29
 
30
30
  Führe anschließend aus:
@@ -82,6 +82,7 @@ b4um:pagination
82
82
  b4um:infinite_scroll
83
83
  b4um:search
84
84
  b4um:sortable
85
+ b4um:todo
85
86
  b4um:comments
86
87
  b4um:in_place
87
88
  b4um:authentication
@@ -1146,6 +1147,119 @@ Dadurch entstehen entsprechend `/produktuebersicht`, `/verwaltung` und `/admin`.
1146
1147
  Eine separate Sortierseite ermöglicht außerdem, nur die `sort`-Action durch die Authentifizierung zu schützen, während
1147
1148
  der normale Ressourcen-Index öffentlich bleiben kann.
1148
1149
 
1150
+ ## Todo
1151
+
1152
+ Erzeuge eine vollständige Todo-Anwendung mit Turbo Streams, Stimulus und dem einheitlichen b4um-Styling:
1153
+
1154
+ ```bash
1155
+ bin/rails generate b4um:todo Task
1156
+ bin/rails db:migrate
1157
+ ```
1158
+
1159
+ Der Generator erstellt eine sofort verwendbare Aufgabenliste, ohne dass ein zusätzliches Todo-Gem erforderlich ist.
1160
+
1161
+ Standardmäßig werden Aufgaben gemeinsam innerhalb der Anwendung verwaltet und sind keinem einzelnen Benutzer zugeordnet.
1162
+
1163
+ Die generierte Todo-Anwendung ist erreichbar unter:
1164
+
1165
+ ```text
1166
+ /tasks
1167
+ ```
1168
+
1169
+ ### Funktionen
1170
+
1171
+ Der Todo-Generator bietet:
1172
+
1173
+ - Neue Aufgaben erstellen
1174
+ - Aufgaben als erledigt markieren
1175
+ - Erledigte Aufgaben wieder öffnen
1176
+ - Aufgaben löschen
1177
+ - Getrennte Listen für offene und erledigte Aufgaben
1178
+ - Automatische Aufgabenzähler
1179
+ - Fortschrittsbalken mit prozentualer Anzeige
1180
+ - Aktualisierungen mit Turbo Streams ohne vollständiges Neuladen der Seite
1181
+ - Stimulus-Controller für die Aufgabeneingabe
1182
+ - Automatisches Zurücksetzen des Eingabefeldes nach erfolgreicher Erstellung
1183
+ - b4um Floating Labels
1184
+ - Responsives b4um-Kartenlayout
1185
+ - Unterstützung für Light Mode und Dark Mode
1186
+ - Optionale Zuordnung zu einem Benutzerkonto
1187
+ - Zugriffsschutz für benutzerspezifische Aufgaben
1188
+
1189
+ ### Persönliche Todo-Listen
1190
+
1191
+ Todo-Listen können optional einem Authentifizierungsmodell zugeordnet werden.
1192
+
1193
+ Mit `--owner` werden Aufgaben einzelnen Benutzern zugewiesen:
1194
+
1195
+ ```bash
1196
+ bin/rails generate b4um:todo Task --owner=User
1197
+ bin/rails db:migrate
1198
+ ```
1199
+
1200
+ Das angegebene Benutzer- beziehungsweise Eigentümermodell muss bereits existieren.
1201
+
1202
+ Wird ein Eigentümermodell angegeben, erhält jedes angemeldete Benutzerkonto seine eigene Todo-Liste.
1203
+
1204
+ Die Aufgaben werden über die Verknüpfung des aktuell angemeldeten Kontos geladen. Dadurch können Benutzer nicht auf
1205
+ Aufgaben anderer Konten zugreifen.
1206
+
1207
+ Nicht authentifizierte Anfragen an benutzerspezifische Todo-Aktionen erhalten den HTTP-Status `401 Unauthorized`.
1208
+
1209
+ ### Integration mit der Authentifizierung
1210
+
1211
+ Der Todo-Generator arbeitet mit dem bestehenden b4um-Authentifizierungssystem zusammen.
1212
+
1213
+ Ein vollständiges Beispiel:
1214
+
1215
+ ```bash
1216
+ bin/rails generate b4um:scaffold User name:string email:string password_digest:string
1217
+ bin/rails db:migrate
1218
+
1219
+ bin/rails generate b4um:authentication User
1220
+
1221
+ bin/rails generate b4um:todo Task --owner=User
1222
+ bin/rails db:migrate
1223
+ ```
1224
+
1225
+ Die Passwort-Authentifizierung benötigt bcrypt. Dieses kann über `b4um:install` installiert werden.
1226
+
1227
+ Die Option `--owner` unterstützt auch andere Authentifizierungsmodelle:
1228
+
1229
+ ```bash
1230
+ bin/rails generate b4um:todo Task --owner=Member
1231
+ bin/rails generate b4um:todo Task --owner=Customer
1232
+ ```
1233
+
1234
+ Der generierte Controller verwendet automatisch den zum Modell passenden Helper für das aktuell angemeldete Konto:
1235
+
1236
+ ```ruby
1237
+ current_user
1238
+ current_member
1239
+ current_customer
1240
+ ```
1241
+
1242
+ ### Generierte Dateien
1243
+
1244
+ Für das standardmäßige `Task`-Modell erstellt der Generator folgende Komponenten:
1245
+
1246
+ - Task-Modell und Datenbankmigration
1247
+ - Tasks-Controller
1248
+ - Ressourcen-Routen
1249
+ - Todo-Index-View
1250
+ - Task-Partial
1251
+ - Fortschritts-Partial
1252
+ - Todo-Stylesheet
1253
+ - Stimulus-Controller
1254
+
1255
+ Nach dem Generieren muss die Datenbankmigration ausgeführt werden:
1256
+
1257
+ ```bash
1258
+ bin/rails db:migrate
1259
+ ```
1260
+
1261
+ Anschließend kann die Todo-Anwendung verwendet werden.
1262
+
1149
1263
  ## Kommentare
1150
1264
 
1151
1265
  Füge einem bestehenden Modell polymorphe Kommentare hinzu:
@@ -1549,7 +1663,7 @@ wird.
1549
1663
 
1550
1664
  ## Version
1551
1665
 
1552
- Aktuelle Version: `0.4.0`
1666
+ Aktuelle Version: `0.5.0`
1553
1667
 
1554
1668
  ## Autor
1555
1669
 
data/README.md CHANGED
@@ -6,8 +6,8 @@ b4um Generators is a collection of reusable Rails generators, templates, compone
6
6
  Rails projects.
7
7
 
8
8
  The gem provides a consistent starting point for Rails applications and includes generators for scaffolds, controllers,
9
- Bento layouts, tables, pagination, infinite scrolling, search, sorting, comments, authentication, administrator
10
- management, guest access, attachments and rich-text editing.
9
+ Bento layouts, tables, pagination, infinite scrolling, search, sorting, Todo lists, comments, authentication,
10
+ administrator management, guest access, attachments and rich-text editing.
11
11
 
12
12
  Generated components share the same b4um styling and are designed to work together.
13
13
 
@@ -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.5.0", path: "/path/to/b4um_generators"
27
27
  ```
28
28
 
29
29
  Then run:
@@ -80,6 +80,7 @@ b4um:pagination
80
80
  b4um:infinite_scroll
81
81
  b4um:search
82
82
  b4um:sortable
83
+ b4um:todo
83
84
  b4um:comments
84
85
  b4um:in_place
85
86
  b4um:authentication
@@ -1125,6 +1126,119 @@ These create `/produktuebersicht`, `/verwaltung`, and `/admin` respectively.
1125
1126
  Using a separate sortable page also makes it possible to protect only the `sort` action with authentication while
1126
1127
  keeping the regular resource index public.
1127
1128
 
1129
+ ## Todo
1130
+
1131
+ Generate a complete Todo application with Turbo Streams, Stimulus and b4um styling:
1132
+
1133
+ ```bash
1134
+ bin/rails generate b4um:todo Task
1135
+ bin/rails db:migrate
1136
+ ```
1137
+
1138
+ The generator creates a ready-to-use Todo list without requiring an additional Todo gem.
1139
+
1140
+ By default, tasks are shared across the application and are not assigned to individual users.
1141
+
1142
+ The generated Todo application is available at:
1143
+
1144
+ ```text
1145
+ /tasks
1146
+ ```
1147
+
1148
+ ### Features
1149
+
1150
+ The Todo generator provides:
1151
+
1152
+ - Create new tasks
1153
+ - Mark tasks as completed
1154
+ - Reopen completed tasks
1155
+ - Delete tasks
1156
+ - Separate lists for open and completed tasks
1157
+ - Automatic task counters
1158
+ - Progress bar with completion percentage
1159
+ - Turbo Stream updates without full page reloads
1160
+ - Stimulus controller for task input handling
1161
+ - Automatic input reset after successful creation
1162
+ - b4um floating labels
1163
+ - Responsive b4um card layout
1164
+ - Light and dark mode support
1165
+ - Optional owner association
1166
+ - Owner-specific task access protection
1167
+
1168
+ ### Personal Todo Lists
1169
+
1170
+ Todo lists can optionally be associated with an authentication model.
1171
+
1172
+ Use `--owner` to assign tasks to individual users:
1173
+
1174
+ ```bash
1175
+ bin/rails generate b4um:todo Task --owner=User
1176
+ bin/rails db:migrate
1177
+ ```
1178
+
1179
+ The owner model must already exist.
1180
+
1181
+ When an owner is configured, each authenticated account has its own Todo list.
1182
+
1183
+ Tasks are loaded through the current owner's association, preventing users from accessing tasks belonging to another
1184
+ account.
1185
+
1186
+ Unauthenticated requests to owner-specific Todo actions receive HTTP `401 Unauthorized`.
1187
+
1188
+ ### Authentication Integration
1189
+
1190
+ The Todo generator integrates with the existing b4um authentication system.
1191
+
1192
+ A complete example:
1193
+
1194
+ ```bash
1195
+ bin/rails generate b4um:scaffold User name:string email:string password_digest:string
1196
+ bin/rails db:migrate
1197
+
1198
+ bin/rails generate b4um:authentication User
1199
+
1200
+ bin/rails generate b4um:todo Task --owner=User
1201
+ bin/rails db:migrate
1202
+ ```
1203
+
1204
+ Password authentication requires bcrypt, which can be installed through `b4um:install`.
1205
+
1206
+ The owner option also supports other authentication models:
1207
+
1208
+ ```bash
1209
+ bin/rails generate b4um:todo Task --owner=Member
1210
+ bin/rails generate b4um:todo Task --owner=Customer
1211
+ ```
1212
+
1213
+ The generated controller uses the corresponding current account helper:
1214
+
1215
+ ```ruby
1216
+ current_user
1217
+ current_member
1218
+ current_customer
1219
+ ```
1220
+
1221
+ ### Generated Files
1222
+
1223
+ For the default `Task` model, the generator creates the following components:
1224
+
1225
+ - Task model and database migration
1226
+ - Tasks controller
1227
+ - Resource routes
1228
+ - Todo index view
1229
+ - Task partial
1230
+ - Progress partial
1231
+ - Todo stylesheet
1232
+ - Stimulus controller
1233
+
1234
+ After generation, run:
1235
+
1236
+ ```bash
1237
+ bin/rails db:migrate
1238
+ ```
1239
+
1240
+ The Todo application is then ready to use.
1241
+
1128
1242
  ## Comments
1129
1243
 
1130
1244
  Add polymorphic comments to an existing model:
@@ -1524,7 +1638,7 @@ The gem can be tested locally by referencing the repository with `path:` from a
1524
1638
 
1525
1639
  ## Version
1526
1640
 
1527
- Current version: `0.4.0`
1641
+ Current version: `0.5.0`
1528
1642
 
1529
1643
  ## Author
1530
1644
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module B4umGenerators
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
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(