lib/js_routes/instance.rb in js-routes-2.2.10 vs lib/js_routes/instance.rb in js-routes-2.3.0
- old
+ new
@@ -22,13 +22,20 @@
end
sig {returns(String)}
def generate
# Ensure routes are loaded. If they're not, load them.
+
application = T.unsafe(self.application)
- if named_routes.empty? && application.respond_to?(:reload_routes!, true)
- application.reload_routes!
+ if named_routes.empty?
+ if application.is_a?(Rails::Application)
+ if Rails.version >= "8.0.0"
+ application.reload_routes_unless_loaded
+ else
+ application.reload_routes!
+ end
+ end
end
content = File.read(@configuration.source_file)
unless @configuration.dts?
content = js_variables.inject(content) do |js, (key, value)|
@@ -176,12 +183,12 @@
end
sig { params(route: JourneyRoute).returns(T::Array[StringArray]) }
def mounted_app_routes(route)
rails_engine_app = T.unsafe(app_from_route(route))
- if rails_engine_app.respond_to?(:superclass) &&
- rails_engine_app.superclass == Rails::Engine && !route.path.anchored
+ if rails_engine_app.is_a?(Class) &&
+ rails_engine_app < Rails::Engine && !route.path.anchored
rails_engine_app.routes.named_routes.flat_map do |_, engine_route|
route_helpers_if_match(engine_route, route)
end
else
[]
@@ -189,12 +196,12 @@
end
sig { params(route: JourneyRoute).returns(T.untyped) }
def app_from_route(route)
app = route.app
- # rails engine in Rails 4.2 use additional
+ # Rails Engine can use additional
# ActionDispatch::Routing::Mapper::Constraints, which contain app
- if app.respond_to?(:app) && app.respond_to?(:constraints)
+ if app.is_a?(ActionDispatch::Routing::Mapper::Constraints)
app.app
else
app
end
end