Skip to content

Commit e2607fb

Browse files
committed
Consistent routes extraction from app
1 parent 8496e08 commit e2607fb

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/js_routes/instance.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def generate
2626
# Ensure routes are loaded. If they're not, load them.
2727

2828
application = T.unsafe(self.application)
29-
if named_routes.empty?
29+
if routes_from(application).empty?
3030
if application.is_a?(Rails::Application)
3131
if Rails.version >= "8.0.0"
3232
T.unsafe(application).reload_routes_unless_loaded
@@ -135,9 +135,9 @@ def json(value)
135135
JsRoutes.json(value)
136136
end
137137

138-
sig { returns(T::Hash[Symbol, JourneyRoute]) }
139-
def named_routes
140-
T.unsafe(application).routes.named_routes.to_h
138+
sig {params(application: Application).returns(T::Array[JourneyRoute])}
139+
def routes_from(application)
140+
T.unsafe(application).routes.named_routes.to_h.values.sort_by(&:name)
141141
end
142142

143143
sig { returns(String) }
@@ -186,7 +186,7 @@ def export_separator
186186

187187
sig { returns(T::Array[StringArray]) }
188188
def routes_list
189-
named_routes.sort_by(&:first).flat_map do |_, route|
189+
routes_from(application).flat_map do |route|
190190
route_helpers_if_match(route) + mounted_app_routes(route)
191191
end
192192
end
@@ -196,7 +196,7 @@ def mounted_app_routes(route)
196196
rails_engine_app = T.unsafe(app_from_route(route))
197197
if rails_engine_app.is_a?(Class) &&
198198
rails_engine_app < Rails::Engine && !route.path.anchored
199-
T.unsafe(rails_engine_app).routes.named_routes.flat_map do |_, engine_route|
199+
routes_from(rails_engine_app).flat_map do |engine_route|
200200
route_helpers_if_match(engine_route, route)
201201
end
202202
else

0 commit comments

Comments
 (0)