bullet_train-super_scaffolding 1.8.2 → 1.8.4
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 +4 -4
- data/lib/bullet_train/super_scaffolding/version.rb +1 -1
- data/lib/bullet_train/super_scaffolding.rb +2 -1
- data/lib/generators/super_scaffold/audit_logs/USAGE +22 -0
- data/lib/generators/super_scaffold/audit_logs/audit_logs_generator.rb +26 -0
- data/lib/scaffolding/routes_file_manipulator.rb +60 -14
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fd34927138c9c4d62670e1cd4db49b074182fdafd559911c7a21614d31d0b99
|
4
|
+
data.tar.gz: e210ebe306a8c89bb453dcb6d5d9c732d8a783432a790c5f48c4cc5fe9a33525
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d787a123c710490675403e27c0560627d29c031f297252c8a4f3bd051d4968813c58ad2c8001d214d536cab872ed8058efcd38e16f5cb2a3e875a85787c6622
|
7
|
+
data.tar.gz: 88c909ec4c12c78e15e93257a87b3d03e26782a81125bc4664723154bdb41afa828d6ec193cd29de174516c5ae9083634dcc5a1bc1c8ec73aeacbc6ec0cfc35f
|
@@ -22,7 +22,8 @@ module BulletTrain
|
|
22
22
|
"action-models:targets-one" => "BulletTrain::ActionModels::Scaffolders::TargetsOneScaffolder",
|
23
23
|
"action-models:targets-one-parent" => "BulletTrain::ActionModels::Scaffolders::TargetsOneParentScaffolder",
|
24
24
|
"action-models:performs-export" => "BulletTrain::ActionModels::Scaffolders::PerformsExportScaffolder",
|
25
|
-
"action-models:performs-import" => "BulletTrain::ActionModels::Scaffolders::PerformsImportScaffolder"
|
25
|
+
"action-models:performs-import" => "BulletTrain::ActionModels::Scaffolders::PerformsImportScaffolder",
|
26
|
+
"audit-logs" => "BulletTrain::AuditLogs::Scaffolders::AuditLogScaffolder"
|
26
27
|
}
|
27
28
|
|
28
29
|
class Runner
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Description:
|
2
|
+
Generate files needed to add an audit log to a model.
|
3
|
+
|
4
|
+
Example:
|
5
|
+
E.g. Add audit logs to Posts from a Team.
|
6
|
+
rails generate super_scaffold:audit_logs Post Team name:text_field
|
7
|
+
|
8
|
+
The attributes you specify will be added to the _version partial and used to show different versions of the model.
|
9
|
+
|
10
|
+
This will create:
|
11
|
+
db/migrate/20241115152914_add_project_to_activity_versions.rb
|
12
|
+
app/views/account/projects/_version.html.erb'.
|
13
|
+
And update:
|
14
|
+
app/models/project.rb
|
15
|
+
app/models/activity/version.rb
|
16
|
+
app/views/account/projects/show.html.erb
|
17
|
+
app/models/activity/version.rb
|
18
|
+
config/routes.rb
|
19
|
+
app/controllers/account/projects_controller.rb
|
20
|
+
|
21
|
+
🏆 Protip: Commit your other changes before running Super Scaffolding so it's easy to undo if you (or we) make any mistakes.
|
22
|
+
If you do that, you can reset to your last commit state by using `git checkout .` and `git clean -d -f`.
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative "../super_scaffold_base"
|
2
|
+
require "scaffolding/routes_file_manipulator"
|
3
|
+
|
4
|
+
class AuditLogsGenerator < Rails::Generators::Base
|
5
|
+
include SuperScaffoldBase
|
6
|
+
|
7
|
+
source_root File.expand_path("templates", __dir__)
|
8
|
+
|
9
|
+
namespace "super_scaffold:audit_logs"
|
10
|
+
|
11
|
+
argument :target_model, type: :string
|
12
|
+
argument :parent_model, type: :string
|
13
|
+
argument :attributes, type: :array, banner: "attribute:type attribute:type"
|
14
|
+
|
15
|
+
def generate
|
16
|
+
if defined?(BulletTrain::AuditLogs)
|
17
|
+
# We add the name of the specific super_scaffolding command that we want to
|
18
|
+
# invoke to the beginning of the argument string.
|
19
|
+
ARGV.unshift "audit-logs"
|
20
|
+
BulletTrain::SuperScaffolding::Runner.new.run
|
21
|
+
else
|
22
|
+
puts "You must have AuditLogs installed if you want to use this generator.".red
|
23
|
+
puts "Please refer to the documentation for more information: https://bullettrain.co/docs/audit-logs"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -158,6 +158,33 @@ class Scaffolding::RoutesFileManipulator
|
|
158
158
|
namespace_block_start.present? ? {namespace => namespace_block_start} : {}
|
159
159
|
end
|
160
160
|
|
161
|
+
def find_last_in_namespace(needle, namespaces, within = nil, ignore = nil)
|
162
|
+
if namespaces.any?
|
163
|
+
namespace_lines = find_namespaces(namespaces, within)
|
164
|
+
within = namespace_lines[namespaces.last]
|
165
|
+
end
|
166
|
+
|
167
|
+
lines_within = Scaffolding::FileManipulator.lines_within(lines, within)
|
168
|
+
lines_within.reverse.each_with_index do |line, line_number|
|
169
|
+
reversed_line_number = lines_within.count - line_number - 1
|
170
|
+
# + 2 because line_number starts from 0, and within starts one line after
|
171
|
+
actual_line_number = (within + reversed_line_number + 2)
|
172
|
+
|
173
|
+
# The lines we want to ignore may be a a series of blocks, so we check each Range here.
|
174
|
+
ignore_line = false
|
175
|
+
if ignore.present?
|
176
|
+
ignore.each do |lines_to_ignore|
|
177
|
+
ignore_line = true if lines_to_ignore.include?(actual_line_number)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
next if ignore_line
|
182
|
+
return (within + (within ? 1 : 0) + reversed_line_number) if line.match?(needle)
|
183
|
+
end
|
184
|
+
|
185
|
+
nil
|
186
|
+
end
|
187
|
+
|
161
188
|
def find_in_namespace(needle, namespaces, within = nil, ignore = nil)
|
162
189
|
if namespaces.any?
|
163
190
|
namespace_lines = find_namespaces(namespaces, within)
|
@@ -187,15 +214,26 @@ class Scaffolding::RoutesFileManipulator
|
|
187
214
|
within = options[:within]
|
188
215
|
parts = parts.dup
|
189
216
|
resource = parts.pop
|
217
|
+
needle = /resources :#{resource}#{options[:options] ? ", #{options[:options].gsub(/({)(.*)(})/, '{\2}')}" : ""}(,?\s.*)? do(\s.*)?$/
|
218
|
+
|
190
219
|
# TODO this doesn't take into account any options like we do in `find_resource`.
|
191
|
-
|
220
|
+
if options[:find_last]
|
221
|
+
find_last_in_namespace(needle, parts, within)
|
222
|
+
else
|
223
|
+
find_in_namespace(needle, parts, within)
|
224
|
+
end
|
192
225
|
end
|
193
226
|
|
194
227
|
def find_resource(parts, options = {})
|
195
228
|
parts = parts.dup
|
196
229
|
resource = parts.pop
|
197
230
|
needle = /resources :#{resource}#{options[:options] ? ", #{options[:options].gsub(/({)(.*)(})/, '{\2}')}" : ""}(,?\s.*)?$/
|
198
|
-
|
231
|
+
|
232
|
+
if options[:find_last]
|
233
|
+
find_last_in_namespace(needle, parts, options[:within], options[:ignore])
|
234
|
+
else
|
235
|
+
find_in_namespace(needle, parts, options[:within], options[:ignore])
|
236
|
+
end
|
199
237
|
end
|
200
238
|
|
201
239
|
def find_or_create_resource(parts, options = {})
|
@@ -278,17 +316,18 @@ class Scaffolding::RoutesFileManipulator
|
|
278
316
|
end
|
279
317
|
|
280
318
|
def find_or_convert_resource_block(parent_resource, options = {})
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
raise BulletTrain::SuperScaffolding::CannotFindParentResourceException.new("the parent resource (`#{parent_resource}`) doesn't appear to exist in `#{@filename}`.")
|
319
|
+
resource_statement_line = find_resource([parent_resource], options)
|
320
|
+
if resource_statement_line
|
321
|
+
resource_statement = lines[resource_statement_line]
|
322
|
+
if !resource_statement.match?(/ do(\s.*)?$/)
|
323
|
+
lines[resource_statement_line].gsub!("\n", " do\n")
|
324
|
+
insert_after(["end"], resource_statement_line)
|
288
325
|
end
|
326
|
+
else
|
327
|
+
raise BulletTrain::SuperScaffolding::CannotFindParentResourceException.new("the parent resource (`#{parent_resource}`) doesn't appear to exist in `#{@filename}`.")
|
289
328
|
end
|
290
329
|
|
291
|
-
#
|
330
|
+
# capture the line number of the block of code we're working within.
|
292
331
|
unless (within = find_resource_block([parent_resource], options))
|
293
332
|
raise "tried to convert the parent resource to a block, but failed?"
|
294
333
|
end
|
@@ -328,13 +367,18 @@ class Scaffolding::RoutesFileManipulator
|
|
328
367
|
# end
|
329
368
|
# end
|
330
369
|
|
331
|
-
parent_within =
|
370
|
+
parent_within = find_resource([parent_resource], within: within)
|
371
|
+
|
372
|
+
# With deeply nested namespaces we end up with mutliple resource blocks and some things need
|
373
|
+
# to go into the last block. See this issue for details:
|
374
|
+
# https://github.com/bullet-train-co/bullet_train/issues/1655
|
375
|
+
last_parent_within = find_or_convert_resource_block(parent_resource, within: within, find_last: true)
|
332
376
|
|
333
377
|
# add the new resource within that namespace.
|
334
378
|
line = "scope module: '#{parent_resource}' do"
|
335
379
|
# TODO you haven't tested this yet.
|
336
|
-
unless (scope_within = Scaffolding::FileManipulator.find(lines, /#{line}/,
|
337
|
-
scope_within = insert([line, "end"],
|
380
|
+
unless (scope_within = Scaffolding::FileManipulator.find(lines, /#{line}/, last_parent_within))
|
381
|
+
scope_within = insert([line, "end"], last_parent_within)
|
338
382
|
end
|
339
383
|
|
340
384
|
if child_namespaces.size > 1
|
@@ -361,7 +405,9 @@ class Scaffolding::RoutesFileManipulator
|
|
361
405
|
else
|
362
406
|
routing_options = "only: collection_actions"
|
363
407
|
routing_options += ", #{formatted_concerns}" if formatted_concerns
|
364
|
-
|
408
|
+
# We find last here for this reason:
|
409
|
+
# https://github.com/bullet-train-co/bullet_train/issues/1655
|
410
|
+
find_or_create_resource([child_resource], options: routing_options, within: scope_within, find_last: true)
|
365
411
|
|
366
412
|
# namespace :projects do
|
367
413
|
# resources :deliverables, except: collection_actions
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullet_train-super_scaffolding
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Culver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: standard
|
@@ -174,6 +174,8 @@ files:
|
|
174
174
|
- lib/generators/super_scaffold/action_models/targets_one/targets_one_generator.rb
|
175
175
|
- lib/generators/super_scaffold/action_models/targets_one_parent/USAGE
|
176
176
|
- lib/generators/super_scaffold/action_models/targets_one_parent/targets_one_parent_generator.rb
|
177
|
+
- lib/generators/super_scaffold/audit_logs/USAGE
|
178
|
+
- lib/generators/super_scaffold/audit_logs/audit_logs_generator.rb
|
177
179
|
- lib/generators/super_scaffold/conversations/USAGE
|
178
180
|
- lib/generators/super_scaffold/conversations/conversations_generator.rb
|
179
181
|
- lib/generators/super_scaffold/field/USAGE
|