@@ -177,6 +177,28 @@ module Routing {
177177 }
178178 }
179179
180+ private Expr getActionFromMethodCall ( MethodCall methodCall ) {
181+ result =
182+ [
183+ // e.g. `get "/comments", to: "comments#index"
184+ methodCall .getKeywordArgument ( "to" ) ,
185+ // e.g. `get "/comments" => "comments#index"
186+ methodCall .getArgument ( 0 ) .( Pair ) .getValue ( )
187+ ]
188+ }
189+
190+ /**
191+ * Gets a string representation of the controller-action pair that is routed
192+ * to by this method call.
193+ */
194+ private string getActionStringFromMethodCall ( MethodCall methodCall ) {
195+ getActionFromMethodCall ( methodCall ) .getConstantValue ( ) .isStringlikeValue ( result )
196+ or
197+ // TODO: use the redirect call argument to resolve the redirect target
198+ getActionFromMethodCall ( methodCall ) .( MethodCall ) .getMethodName ( ) = "redirect" and
199+ result = "<redirect>#<redirect>"
200+ }
201+
180202 /**
181203 * A route block defined by a call to `resources`.
182204 * ```rb
@@ -512,12 +534,7 @@ module Routing {
512534 )
513535 }
514536
515- private string getActionString ( ) {
516- methodCall .getKeywordArgument ( "to" ) .getConstantValue ( ) .isStringlikeValue ( result )
517- or
518- methodCall .getKeywordArgument ( "to" ) .( MethodCall ) .getMethodName ( ) = "redirect" and
519- result = "<redirect>#<redirect>"
520- }
537+ private string getActionString ( ) { result = getActionStringFromMethodCall ( methodCall ) }
521538
522539 override string getAction ( ) {
523540 // get "/photos", action: "index"
@@ -670,11 +687,7 @@ module Routing {
670687 }
671688
672689 override string getLastControllerComponent ( ) {
673- result =
674- extractController ( methodCall
675- .getKeywordArgument ( "to" )
676- .getConstantValue ( )
677- .getStringlikeValue ( ) ) or
690+ result = extractController ( getActionStringFromMethodCall ( methodCall ) ) or
678691 methodCall .getKeywordArgument ( "controller" ) .getConstantValue ( ) .isStringlikeValue ( result ) or
679692 result =
680693 extractController ( methodCall
@@ -704,8 +717,7 @@ module Routing {
704717 }
705718
706719 override string getAction ( ) {
707- result =
708- extractAction ( methodCall .getKeywordArgument ( "to" ) .getConstantValue ( ) .getStringlikeValue ( ) ) or
720+ result = extractAction ( getActionStringFromMethodCall ( methodCall ) ) or
709721 methodCall .getKeywordArgument ( "action" ) .getConstantValue ( ) .isStringlikeValue ( result ) or
710722 result =
711723 extractAction ( methodCall
0 commit comments