@@ -360,12 +360,37 @@ def dispatcher(raise_on_name_error)
360
360
Routing ::RouteSet ::Dispatcher . new raise_on_name_error
361
361
end
362
362
363
- def route_source_location
364
- if Mapper . route_source_locations
365
- action_dispatch_dir = File . expand_path ( ".." , __dir__ )
366
- caller_location = caller_locations . find { |location | !location . path . include? ( action_dispatch_dir ) }
367
- cleaned_path = Mapper . backtrace_cleaner . clean ( [ caller_location . path ] ) . first
368
- "#{ cleaned_path } :#{ caller_location . lineno } " if cleaned_path
363
+ if Thread . respond_to? ( :each_caller_location )
364
+ def route_source_location
365
+ if Mapper . route_source_locations
366
+ action_dispatch_dir = File . expand_path ( ".." , __dir__ )
367
+ Thread . each_caller_location do |location |
368
+ next if location . path . start_with? ( action_dispatch_dir )
369
+
370
+ if cleaned_path = Mapper . backtrace_cleaner . clean_frame ( location . path )
371
+ return "#{ cleaned_path } :#{ location . lineno } "
372
+ else
373
+ return nil
374
+ end
375
+ end
376
+ nil
377
+ end
378
+ end
379
+ else
380
+ def route_source_location
381
+ if Mapper . route_source_locations
382
+ action_dispatch_dir = File . expand_path ( ".." , __dir__ )
383
+ caller_locations . each do |location |
384
+ next if location . path . start_with? ( action_dispatch_dir )
385
+
386
+ if cleaned_path = Mapper . backtrace_cleaner . clean_frame ( location . path )
387
+ return "#{ cleaned_path } :#{ location . lineno } "
388
+ else
389
+ return nil
390
+ end
391
+ end
392
+ nil
393
+ end
369
394
end
370
395
end
371
396
end
0 commit comments