bullet_train-super_scaffolding 1.6.15 → 1.6.17

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: 9d15de6e89509669065c9701bfe3fb3f7b3360d933c1bc7f5d0bb23d2caa9332
4
- data.tar.gz: d68001e7b68cb2b19a975ac7d34bc4ac6fe79a0c67c814fccdcb2b4f0933c43b
3
+ metadata.gz: ab9f39b31aacb0b95619b04fb4b3a32fef367608f8eb4115588dbaf596711c60
4
+ data.tar.gz: a1be9b35f77dfc9871e3909c653d59806519fcc08de8b6a9904a1721348b5b99
5
5
  SHA512:
6
- metadata.gz: 9f4886c91bd90f8cb0345511a6cd3b962f7e53a788f28e94ea1ef52bf95e3cce93c76e52ac8f67c7a8cab7b6516f03f42c9f92950b9b3ba153a875295133a97d
7
- data.tar.gz: 3ee073e9d3116b1aa80298d7d4b1e7c706946af827bee05b2a0e81eb5ed639b7940be52d8ccbf2856b22f502fc92654e25cb27bcbfa978833d1b748df2053293
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.15"
3
+ VERSION = "1.6.17"
4
4
  end
5
5
  end
@@ -35,22 +35,6 @@ class Scaffolding::RoutesFileManipulator
35
35
  @common_namespaces
36
36
  end
37
37
 
38
- # def divergent_namespaces
39
- # unless @divergent_namespaces
40
- # @divergent_namespaces ||= []
41
- # child_parts_copy = child_parts.dup
42
- # parent_parts_copy = parent_parts.dup
43
- # while child_parts_copy.first == parent_parts_copy.first
44
- # child_parts_copy.shift
45
- # parent_parts_copy.shift
46
- # end
47
- # child_parts_copy.pop
48
- # parent_parts_copy.pop
49
- # @divergent_namespaces = [child_parts_copy, parent_parts_copy]
50
- # end
51
- # @divergent_namespaces
52
- # end
53
-
54
38
  def divergent_parts
55
39
  unless @divergent_namespaces
56
40
  @divergent_namespaces ||= []
@@ -68,19 +52,28 @@ class Scaffolding::RoutesFileManipulator
68
52
  end
69
53
 
70
54
  def find_namespaces(namespaces, within = nil)
71
- namespaces = namespaces.dup
72
55
  results = {}
73
- block_end = Scaffolding::BlockManipulator.find_block_end(starting_from: within, lines: lines) if within
74
- lines.each_with_index do |line, line_number|
75
- if within
76
- next unless line_number > within
77
- return results if line_number >= block_end
78
- end
79
- if line.include?("namespace :#{namespaces.first} do")
80
- 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
81
68
  end
82
- return results unless namespaces.any?
83
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
+
84
77
  results
85
78
  end
86
79
 
@@ -434,4 +427,10 @@ class Scaffolding::RoutesFileManipulator
434
427
  lines[line_number].gsub!(/resources :(.*)$/, "resources :\\1, concerns: [#{existing_concerns.map { |e| ":#{e}" }.join(", ")}]")
435
428
  end
436
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
437
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.15
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-16 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
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 6.0.0
41
- - !ruby/object:Gem::Dependency
42
- name: bullet_train
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: masamune-ast
57
43
  requirement: !ruby/object:Gem::Requirement