bullet_train-super_scaffolding 1.6.19 → 1.6.21

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: eafd70da2079b3901c1d863670e76da7058d10eec9aa25158b7b60bfb6599b98
4
- data.tar.gz: 5ee1b5f7fcadae48a99923d5228408cee0d80ce69990907e5882ba234e71505d
3
+ metadata.gz: b8a45fd75e4d864773d49d078b5cd515cb3db2ac48f65e9ca0f783c76d03a411
4
+ data.tar.gz: d22c97723419619595872fcc7cada9985a4f89413b918597a693cffc53b57049
5
5
  SHA512:
6
- metadata.gz: e38a7f78a0e925e3cc7250a8f16ae583315902347f61d9ea2c36d8db88634e60b500f3702c2c2ce5ae23f6df5d3c20c56fd7e1c15f4ec6b33f1eda4a15503892
7
- data.tar.gz: 5cb14fe691394c3656e29e604f09ba1f2e80a7de36efdb717abdf01fb5dee610628feb54b73d4f8d2a18aecfde3f095c8c68e44dd4290a6913acfc54f9abe275
6
+ metadata.gz: b5d5ea9b5ac677d66de59c3af78636d191eba5cb807e7e57a77a1d81ebd7434bdf06cc35f1194c9361bcc9ef1d259af75c8691b67fa572639a1fcaffeb1b3506
7
+ data.tar.gz: 1f90dca07ce654f5d99c5cd5c85687761ae9950672301ea84d3f31c8b1a30e71620d85369a580addb707f3d168d613691631de483bd297783d27c054b0d4d26e
@@ -1,5 +1,5 @@
1
1
  module BulletTrain
2
2
  module SuperScaffolding
3
- VERSION = "1.6.19"
3
+ VERSION = "1.6.21"
4
4
  end
5
5
  end
@@ -54,17 +54,23 @@ class Scaffolding::RoutesFileManipulator
54
54
  def find_namespaces(namespaces, within = nil)
55
55
  namespaces = namespaces.dup
56
56
  results = {}
57
- block_end = Scaffolding::BlockManipulator.find_block_end(starting_from: within, lines: lines) if within
58
- lines.each_with_index do |line, line_number|
59
- if within
60
- next unless line_number > within
61
- return results if line_number >= block_end
62
- end
63
- if line.include?("namespace :#{namespaces.first} do")
64
- results[namespaces.shift] = line_number
65
- end
66
- return results unless namespaces.any?
57
+ reinstantiate_masamune_object
58
+
59
+ # `within` can refer to either a `resources`, `namespace`, `scope`, or `shallow` block.
60
+ blocks = @msmn.method_calls.select { |node| node.token_value.match?(/resources|namespace|scope|shallow/) }
61
+ namespace_nodes = blocks.select { |node| node.token_value.match?(/namespace/) }
62
+
63
+ if within
64
+ starting_block = blocks.find { |block| block.line_number - 1 == within }
65
+ block_range = (starting_block.location.start_line)..(starting_block.location.end_line)
66
+ namespace_nodes.select! { |node| block_range.cover?(node.line_number) }
67
+ end
68
+
69
+ namespace_nodes.each do |node|
70
+ name = node.arguments.child_nodes.first.unescaped
71
+ results[namespaces.shift] = node.line_number - 1 if namespaces.first.to_s == name
67
72
  end
73
+
68
74
  results
69
75
  end
70
76
 
@@ -223,6 +229,7 @@ class Scaffolding::RoutesFileManipulator
223
229
  # all other namespace blocks INSIDE the top-level namespace blocks are skipped
224
230
  if namespace_line_numbers.include?(line_index)
225
231
  # Grab the first symbol token on the same line as the namespace.
232
+ reinstantiate_masamune_object
226
233
  namespace_name = @msmn.symbols.find { |sym| sym.line_number == line_index }.token_value
227
234
  local_namespace = find_namespaces([namespace_name], within)
228
235
  starting_line_number = local_namespace[namespace_name]
@@ -418,4 +425,8 @@ class Scaffolding::RoutesFileManipulator
418
425
  lines[line_number].gsub!(/resources :(.*)$/, "resources :\\1, concerns: [#{existing_concerns.map { |e| ":#{e}" }.join(", ")}]")
419
426
  end
420
427
  end
428
+
429
+ def reinstantiate_masamune_object
430
+ @msmn = Masamune::AbstractSyntaxTree.new(lines.join)
431
+ end
421
432
  end
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.6.19
4
+ version: 1.6.21
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-11-22 00:00:00.000000000 Z
11
+ date: 2023-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: standard