bullet_train-super_scaffolding 1.6.16 → 1.6.17

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: 756d0f0f80e99c6dae67cd43a18cb2c759b0aa8255d4671f25b3cdb415a3c318
4
- data.tar.gz: 764cb6047ffcda07aebd78cc05e525ae4e658ff5fc866c428f9a3962308326eb
3
+ metadata.gz: ab9f39b31aacb0b95619b04fb4b3a32fef367608f8eb4115588dbaf596711c60
4
+ data.tar.gz: a1be9b35f77dfc9871e3909c653d59806519fcc08de8b6a9904a1721348b5b99
5
5
  SHA512:
6
- metadata.gz: 56deea3c0cfb883f813acec3d63f92c6b56e9f51c539f03d93b177a1eff67b85a9504d1b61086e474689827f03db0f70c9e0185745b1ec206ad0e2b9bf62b82d
7
- data.tar.gz: a20d36c4ffca88890982c106c23f31973968296f07da056248331384593bb0d64160527ec3fac1ad9150c7710f93a1618d86c1eb862006b5afb0f600ea7a7ac8
6
+ metadata.gz: 5e8cdceb4b5c68cd44d3425fa499f3f132eb51da96c867dd828c6374f8743e6fc3e1b4ccb78cba391fa8d197fd3bf87bcea87d8209976c1f8d7898dcd69f94af
7
+ data.tar.gz: '099142a8e33347d3c506c40780a65f376295d92ba58231beea2b63fe3a4da71766d44fe894002ecb55e941ebaef769818b56ca2ad07183f35ac17d052f8a99a3'
@@ -1,5 +1,5 @@
1
1
  module BulletTrain
2
2
  module SuperScaffolding
3
- VERSION = "1.6.16"
3
+ VERSION = "1.6.17"
4
4
  end
5
5
  end
@@ -52,19 +52,28 @@ class Scaffolding::RoutesFileManipulator
52
52
  end
53
53
 
54
54
  def find_namespaces(namespaces, within = nil)
55
- namespaces = namespaces.dup
56
55
  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
56
+ 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
+
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
65
68
  end
66
- return results unless namespaces.any?
67
69
  end
70
+
71
+ # `within` uses an Array index whereas Masamune nodes use the actual line number, so we write `within + 1` here.
72
+ 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 }
75
+ end
76
+
68
77
  results
69
78
  end
70
79
 
@@ -418,4 +427,10 @@ class Scaffolding::RoutesFileManipulator
418
427
  lines[line_number].gsub!(/resources :(.*)$/, "resources :\\1, concerns: [#{existing_concerns.map { |e| ":#{e}" }.join(", ")}]")
419
428
  end
420
429
  end
430
+
431
+ # We have to do this because the `lines` object is constantly changing,
432
+ # so we reinstantiate this object wherever necessary.
433
+ def reinstantiate_masamune_object
434
+ @msmn = Masamune::AbstractSyntaxTree.new(lines.join)
435
+ end
421
436
  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.16
4
+ version: 1.6.17
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-17 00:00:00.000000000 Z
11
+ date: 2023-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: standard