@@ -511,6 +511,23 @@ ActionControllerClass getAssociatedControllerClass(ErbFile f) {
511
511
)
512
512
}
513
513
514
+ pragma [ nomagic]
515
+ private string getActionControllerClassRelativePath ( ActionControllerClass cls ) {
516
+ result = cls .getLocation ( ) .getFile ( ) .getRelativePath ( )
517
+ }
518
+
519
+ pragma [ nomagic]
520
+ private string getErbFileRelativePath ( ErbFile templateFile ) {
521
+ result = templateFile .getRelativePath ( ) and
522
+ result .matches ( "%app/views/layouts/%" )
523
+ }
524
+
525
+ bindingset [ result ]
526
+ pragma [ inline_late]
527
+ private string getErbFileRelativePathInlineLate ( ErbFile templateFile ) {
528
+ result = getErbFileRelativePath ( templateFile )
529
+ }
530
+
514
531
// TODO: improve layout support, e.g. for `layout` method
515
532
// https://guides.rubyonrails.org/layouts_and_rendering.html
516
533
/**
@@ -522,15 +539,18 @@ ActionControllerClass getAssociatedControllerClass(ErbFile f) {
522
539
*/
523
540
predicate controllerTemplateFile ( ActionControllerClass cls , ErbFile templateFile ) {
524
541
exists ( string sourcePrefix , string subPath , string controllerPath |
525
- controllerPath = cls . getLocation ( ) . getFile ( ) . getRelativePath ( ) and
542
+ controllerPath = getActionControllerClassRelativePath ( cls ) and
526
543
// `sourcePrefix` is either a prefix path ending in a slash, or empty if
527
544
// the rails app is at the source root
528
545
sourcePrefix = [ controllerPath .regexpCapture ( "^(.*/)app/controllers/(?:.*?)/(?:[^/]*)$" , 1 ) , "" ] and
529
- controllerPath = sourcePrefix + "app/controllers/" + subPath + "_controller.rb" and
530
- (
531
- sourcePrefix + "app/views/" + subPath = templateFile .getParentContainer ( ) .getRelativePath ( )
532
- or
533
- templateFile .getRelativePath ( ) .matches ( sourcePrefix + "app/views/layouts/" + subPath + "%" )
546
+ controllerPath = sourcePrefix + "app/controllers/" + subPath + "_controller.rb"
547
+ |
548
+ sourcePrefix + "app/views/" + subPath = templateFile .getParentContainer ( ) .getRelativePath ( )
549
+ or
550
+ exists ( string path |
551
+ path = getErbFileRelativePath ( _) and
552
+ path .matches ( sourcePrefix + "app/views/layouts/" + subPath + "%" ) and
553
+ path = getErbFileRelativePathInlineLate ( templateFile )
534
554
)
535
555
)
536
556
}
0 commit comments