bullet_train-super_scaffolding 1.3.23 → 1.3.24
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd421ed7beb8f9570ef975c46e9f5794ed1a64253061f67b14e13bc98e677cde
|
4
|
+
data.tar.gz: 135079a96e577d61008e20042616ced3c9d27a85d039e61fc3665f519e4fca00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33f0e7cb5d4011be403d74bd4b1ba6352fa8ef7d50ccdd7f923e0829871def6f9b2f31af93eea2b2ff2f827e68ced6f4d8084bcf4cdc9c460e04ba340b5e3128
|
7
|
+
data.tar.gz: 8ceb683356e4b78eacb8efe373c750c2b8916097cc3b6752e6657fa4481d494a63884460f4643726bef3ed0ef164e3c451e2fb6f8d812680e8298ef70fb2b9ad
|
@@ -34,6 +34,46 @@ module BulletTrain
|
|
34
34
|
parents = argv[1] ? argv[1].split(",") : []
|
35
35
|
parents = parents.map(&:classify).uniq
|
36
36
|
parent = parents.first
|
37
|
+
child_parts = child.split("::")
|
38
|
+
parent_parts = parent.split("::")
|
39
|
+
|
40
|
+
# Pop off however many spaces match.
|
41
|
+
child_parts_dup = child_parts.dup
|
42
|
+
parent_parts_dup = parent_parts.dup
|
43
|
+
parent_without_namespace = nil
|
44
|
+
child_parts_dup.each.with_index do |child_part, idx|
|
45
|
+
if child_part == parent_parts_dup[idx]
|
46
|
+
child_parts.shift
|
47
|
+
parent_parts.shift
|
48
|
+
else
|
49
|
+
parent_without_namespace = parent_parts.join("::")
|
50
|
+
break
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# `tr` here compensates for namespaced models (i.e. - `Projects::Deliverable` to `projects/deliverable`).
|
55
|
+
parent_reference = parent_without_namespace.tableize.singularize.tr("/", "_")
|
56
|
+
tableized_child = child.tableize.tr("/", "_")
|
57
|
+
|
58
|
+
# Pull the parent foreign key from the `create_table` call
|
59
|
+
# if a migration with `add_reference` hasn't been created.
|
60
|
+
migration_file_name = `grep "add_reference :#{tableized_child}, :#{parent_reference}" db/migrate/*`.split(":").shift
|
61
|
+
migration_file_name ||= `grep "create_table :#{tableized_child}" db/migrate/*`.split(":").shift
|
62
|
+
parent_t_references = "t.references :#{parent_reference}"
|
63
|
+
parent_add_reference = "add_reference :#{tableized_child}, :#{parent_reference}"
|
64
|
+
parent_foreign_key = nil
|
65
|
+
File.open(migration_file_name).readlines.each do |line|
|
66
|
+
parent_foreign_key = line.match?(/#{parent_add_reference}|#{parent_t_references}/)
|
67
|
+
break if parent_foreign_key
|
68
|
+
end
|
69
|
+
|
70
|
+
unless parent_foreign_key
|
71
|
+
puts "#{child} does not have a foreign key referencing #{parent}".red
|
72
|
+
puts ""
|
73
|
+
puts "Please re-generate your model, or execute the following to add the foreign key:"
|
74
|
+
puts "rails generate migration add_#{parent_reference}_to_#{tableized_child} #{parent_reference}:references\n"
|
75
|
+
exit 1
|
76
|
+
end
|
37
77
|
|
38
78
|
unless parents.include?("Team")
|
39
79
|
raise "Parents for #{child} should trace back to the Team model, but Team wasn't provided. Please confirm that all of the parents tracing back to the Team model are present and try again.\n" \
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "scaffolding/block_manipulator"
|
2
|
+
require "masamune"
|
2
3
|
|
3
4
|
class Scaffolding::RoutesFileManipulator
|
4
5
|
attr_accessor :child, :parent, :lines, :transformer_options, :concerns
|
@@ -10,6 +11,7 @@ class Scaffolding::RoutesFileManipulator
|
|
10
11
|
@filename = filename
|
11
12
|
self.lines = File.readlines(@filename)
|
12
13
|
self.transformer_options = transformer_options
|
14
|
+
@msmn = Masamune::AbstractSyntaxTree.new(lines.join)
|
13
15
|
end
|
14
16
|
|
15
17
|
def child_parts
|
@@ -225,15 +227,19 @@ class Scaffolding::RoutesFileManipulator
|
|
225
227
|
# Finds namespace blocks no matter how many levels deep they are nested in resource blocks, etc.
|
226
228
|
# However, will not find namespace blocks inside namespace blocks.
|
227
229
|
def top_level_namespace_block_lines(within)
|
230
|
+
namespaces = @msmn.method_calls(name: "namespace")
|
231
|
+
namespace_line_numbers = namespaces.map { |namespace| namespace[:line_number] }
|
232
|
+
|
228
233
|
local_namespace_blocks = []
|
229
234
|
Scaffolding::FileManipulator.lines_within(lines, within).each do |line|
|
230
|
-
#
|
231
|
-
|
235
|
+
# Masamune gets the actual line number, whereas File.readlines etc. start at 0.
|
236
|
+
line_index = lines.index(line) + 1
|
232
237
|
|
233
238
|
# Since we only want top-level namespace blocks, we ensure that
|
234
239
|
# all other namespace blocks INSIDE the top-level namespace blocks are skipped
|
235
|
-
if
|
236
|
-
|
240
|
+
if namespace_line_numbers.include?(line_index)
|
241
|
+
# Grab the first symbol token on the same line as the namespace.
|
242
|
+
namespace_name = @msmn.symbols.find { |sym| sym[:line_number] == line_index }[:token]
|
237
243
|
local_namespace = find_namespaces([namespace_name], within)
|
238
244
|
starting_line_number = local_namespace[namespace_name]
|
239
245
|
local_namespace_block = ((starting_line_number + 1)..(Scaffolding::BlockManipulator.find_block_end(starting_from: starting_line_number, lines: lines) + 1))
|
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.3.
|
4
|
+
version: 1.3.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Culver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: standard
|