bullet_train-super_scaffolding 1.3.22 → 1.3.24

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9210f83ebe43b35a2f22c251699259b4c019dda13edfd97ee8b86a36b1c4076
4
- data.tar.gz: 377c1286afbd0dc549bd606abaf4f4c5eca77461c80586344ebf0cb7905db1fd
3
+ metadata.gz: cd421ed7beb8f9570ef975c46e9f5794ed1a64253061f67b14e13bc98e677cde
4
+ data.tar.gz: 135079a96e577d61008e20042616ced3c9d27a85d039e61fc3665f519e4fca00
5
5
  SHA512:
6
- metadata.gz: df76ecad025409b2d23c5140f5d7b05710bcfd8ac8723c2f6dab2055d83d37f301a17224a9280313829f517a514004b5ecb78837474642365dde18da9f293494
7
- data.tar.gz: 135cb316d50b1d502e2d8803e33de8181252efb6672778107f00e066807e2324668e4f0e1c2f35a1ccdbbb32f3fa23289203ec3cb0098abe6c4593f2db434bca
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,5 +1,5 @@
1
1
  module BulletTrain
2
2
  module SuperScaffolding
3
- VERSION = "1.3.22"
3
+ VERSION = "1.3.24"
4
4
  end
5
5
  end
@@ -8,6 +8,7 @@ require "bullet_train/super_scaffolding/scaffolders/join_model_scaffolder"
8
8
  require "bullet_train/super_scaffolding/scaffolders/oauth_provider_scaffolder"
9
9
 
10
10
  require "indefinite_article"
11
+ require "colorizer"
11
12
 
12
13
  module BulletTrain
13
14
  module SuperScaffolding
@@ -111,8 +111,8 @@ class Scaffolding::Attribute
111
111
  if is_ids?
112
112
  # user_ids should be 'Users'
113
113
  name_without_ids.humanize.titlecase
114
- elsif is_id?
115
- name_without_id.humanize.titlecase
114
+ elsif is_id? && is_vanilla?
115
+ "#{name.humanize.titlecase} ID"
116
116
  else
117
117
  name.humanize.titlecase
118
118
  end
@@ -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
- # i.e. - Retrieve "foo" from "namespace :foo do"
231
- match_data = line.match(/(\s*namespace\s:)(.*)(\sdo$)/)
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 match_data.present?
236
- namespace_name = match_data[2]
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))
@@ -820,7 +820,7 @@ class Scaffolding::Transformer
820
820
 
821
821
  # this gets stripped and is one line, so indentation isn't a problem.
822
822
  field_content = <<-ERB
823
- <%= render 'shared/attributes/#{attribute.partial_name}', attribute: :#{attribute.name_without_id_suffix} %>
823
+ <%= render 'shared/attributes/#{attribute.partial_name}', attribute: :#{attribute.is_vanilla? ? attribute.name : attribute.name_without_id_suffix} %>
824
824
  ERB
825
825
 
826
826
  if attribute.type == "password_field"
@@ -839,7 +839,7 @@ class Scaffolding::Transformer
839
839
  unless cli_options["skip-table"]
840
840
 
841
841
  # table header.
842
- field_content = "<th#{cell_attributes.present? ? " " + cell_attributes : ""}><%= t('.fields.#{attribute.name_without_id_suffix}.heading') %></th>"
842
+ field_content = "<th#{cell_attributes.present? ? " " + cell_attributes : ""}><%= t('.fields.#{attribute.is_vanilla? ? attribute.name : attribute.name_without_id_suffix}.heading') %></th>"
843
843
 
844
844
  unless ["Team", "User"].include?(child)
845
845
  scaffold_add_line_to_file("./app/views/account/scaffolding/completely_concrete/tangible_things/_index.html.erb", field_content, "<%# 🚅 super scaffolding will insert new field headers above this line. %>", prepend: true)
@@ -867,7 +867,7 @@ class Scaffolding::Transformer
867
867
 
868
868
  # this gets stripped and is one line, so indentation isn't a problem.
869
869
  field_content = <<-ERB
870
- <td#{cell_attributes}><%= render 'shared/attributes/#{attribute.partial_name}', attribute: :#{attribute.name_without_id_suffix}#{", #{table_cell_options.join(", ")}" if table_cell_options.any?} %></td>
870
+ <td#{cell_attributes}><%= render 'shared/attributes/#{attribute.partial_name}', attribute: :#{attribute.is_vanilla? ? attribute.name : attribute.name_without_id_suffix}#{", #{table_cell_options.join(", ")}" if table_cell_options.any?} %></td>
871
871
  ERB
872
872
 
873
873
  if attribute.type == "password_field"
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.22
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-01 00:00:00.000000000 Z
11
+ date: 2023-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: standard