bullet_train-super_scaffolding 1.6.18 → 1.6.20

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: 71ecc941a9a4ee421299d14d35a6ef5a437214882dc364eb820c64ce8f35da7b
4
- data.tar.gz: 4fbaaa2c7b7adb9a6e2df372e31f4310cacfdbbff72aa0eebba9b5148be33059
3
+ metadata.gz: 753c1abfff3d8c420ad980d7b7346429225267918becdd9c5a91682dffc8247d
4
+ data.tar.gz: 157b9e1c7747cd41d59611043ad339ab0d42ef485f1b16882648a803cec2b0df
5
5
  SHA512:
6
- metadata.gz: 8f2dfc1a15b9fe1c40553a36675f3969577c614673f0c7191eb7524322b94295806432155df2f25c1926744479df9a69925d6f54852452db8bf602c727d493e5
7
- data.tar.gz: 26cc15d1982e7ee5443794502f21ee55a6a45bf85c6c8a0f2e3913bdc3299586d346d836649cad0d9c9da2c8e2bba1ccb01dbb93b67975bd09cb0f6c3f953e74
6
+ metadata.gz: 5f3f9710da57086521693f17a5e9d2c5cf8f1fa55f1c2fd3b7e848c26a80ba52ed3b36d6a26ad2b0ae900efc6712896daf34a41854660917bc8140c48ef3cb99
7
+ data.tar.gz: c4e500fdb776490d8698863551aeeb6b23e0127dcda35e79bcc21bc28bc7f696502296d45ba3925e46a1bef6618385114c051703550e28e24011fd8c3655833b
@@ -1,5 +1,5 @@
1
1
  module BulletTrain
2
2
  module SuperScaffolding
3
- VERSION = "1.6.18"
3
+ VERSION = "1.6.20"
4
4
  end
5
5
  end
@@ -52,26 +52,23 @@ class Scaffolding::RoutesFileManipulator
52
52
  end
53
53
 
54
54
  def find_namespaces(namespaces, within = nil)
55
+ namespaces = namespaces.dup
55
56
  results = {}
56
57
  reinstantiate_masamune_object
57
- namespace_nodes = @msmn.method_calls(token_value: "namespace")
58
- namespace_nodes.map do |node|
59
- # Get the first argument (a Symbol) without the colon from the list of arguments.
60
- name = node.arguments.child_nodes.first.unescaped
61
58
 
62
- # TODO: For some reason we use both strings and symbols for namespaces.
63
- # i.e. - ["account"] and [:v1].
64
- if namespaces.include?(name.to_sym)
65
- results[name.to_sym] = node.line_number - 1
66
- elsif namespaces.include?(name)
67
- results[name] = node.line_number - 1
68
- end
69
- end
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/) }
70
62
 
71
- # `within` uses an Array index whereas Masamune nodes use the actual line number, so we write `within + 1` here.
72
63
  if within
73
- block_end = @msmn.method_calls.find { |node| node.line_number == within + 1 }.location.end_line
74
- results.reject! { |name, line_number| line_number >= block_end }
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
75
72
  end
76
73
 
77
74
  results
@@ -232,6 +229,7 @@ class Scaffolding::RoutesFileManipulator
232
229
  # all other namespace blocks INSIDE the top-level namespace blocks are skipped
233
230
  if namespace_line_numbers.include?(line_index)
234
231
  # Grab the first symbol token on the same line as the namespace.
232
+ reinstantiate_masamune_object
235
233
  namespace_name = @msmn.symbols.find { |sym| sym.line_number == line_index }.token_value
236
234
  local_namespace = find_namespaces([namespace_name], within)
237
235
  starting_line_number = local_namespace[namespace_name]
@@ -428,8 +426,6 @@ class Scaffolding::RoutesFileManipulator
428
426
  end
429
427
  end
430
428
 
431
- # We have to do this because the `lines` object is constantly changing,
432
- # so we reinstantiate this object wherever necessary.
433
429
  def reinstantiate_masamune_object
434
430
  @msmn = Masamune::AbstractSyntaxTree.new(lines.join)
435
431
  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.18
4
+ version: 1.6.20
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-21 00:00:00.000000000 Z
11
+ date: 2023-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: standard