Skip to content

Commit 7bf168d

Browse files
committed
update rilas/convert_routes_2_3_to_3_0
1 parent 39f2b07 commit 7bf168d

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/rails/convert_routes_2_3_to_3_0.rb

+9-8
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989

9090
helper_method :extract_controller_action_name do |hash_node|
9191
controller_name = hash_node.controller_value.to_value
92-
action_name = hash_node.action_value.to_value
92+
action_name = hash_node.action_value&.to_value || 'index'
9393
"#{controller_name}##{action_name}"
9494
end
9595

@@ -179,6 +179,8 @@
179179
with_node node_type: 'call_node', name: 'with_options', block: { node_type: 'block_node' } do
180180
new_routes = []
181181
node.block.body.body.each do |child_node|
182+
next if child_node.arguments.nil?
183+
182184
url = child_node.arguments.arguments.first.to_value
183185
hash_node = child_node.arguments.arguments.last
184186
if hash_node.action_value || url !~ /:action/
@@ -217,17 +219,16 @@
217219
name: { in: ['resource', 'resources'] },
218220
arguments: { node_type: 'arguments_node', arguments: { size: 2, last: { node_type: 'keyword_hash_node' } } } do
219221
hash_argument = node.arguments.arguments.last
220-
new_routes = ''
222+
new_routes = []
221223
if !hash_argument.collection_value.nil? || !hash_argument.member_value.nil?
222224
collection_routes = hash_argument.collection_value
223225
member_routes = hash_argument.member_value
224226
other_options_code = reject_keys_from_hash(hash_argument, :collection, :member)
225-
new_routes = []
226-
new_routes << if other_options_code.length > 0
227-
"{{message}} {{arguments.arguments.first}}, #{other_options_code} do\n"
228-
else
229-
"{{message}} {{arguments.arguments.first}} do\n"
230-
end
227+
if other_options_code.length > 0
228+
new_routes << "{{message}} {{arguments.arguments.first}}, #{other_options_code} do\n"
229+
else
230+
new_routes << "{{message}} {{arguments.arguments.first}} do\n"
231+
end
231232
new_routes << generate_new_collection_routes(collection_routes) if collection_routes
232233
new_routes << generate_new_member_routes(member_routes) if member_routes
233234
else

0 commit comments

Comments
 (0)