@@ -177,6 +177,28 @@ module Routing {
177
177
}
178
178
}
179
179
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
+
180
202
/**
181
203
* A route block defined by a call to `resources`.
182
204
* ```rb
@@ -512,12 +534,7 @@ module Routing {
512
534
)
513
535
}
514
536
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 ) }
521
538
522
539
override string getAction ( ) {
523
540
// get "/photos", action: "index"
@@ -670,11 +687,7 @@ module Routing {
670
687
}
671
688
672
689
override string getLastControllerComponent ( ) {
673
- result =
674
- extractController ( methodCall
675
- .getKeywordArgument ( "to" )
676
- .getConstantValue ( )
677
- .getStringlikeValue ( ) ) or
690
+ result = extractController ( getActionStringFromMethodCall ( methodCall ) ) or
678
691
methodCall .getKeywordArgument ( "controller" ) .getConstantValue ( ) .isStringlikeValue ( result ) or
679
692
result =
680
693
extractController ( methodCall
@@ -704,8 +717,7 @@ module Routing {
704
717
}
705
718
706
719
override string getAction ( ) {
707
- result =
708
- extractAction ( methodCall .getKeywordArgument ( "to" ) .getConstantValue ( ) .getStringlikeValue ( ) ) or
720
+ result = extractAction ( getActionStringFromMethodCall ( methodCall ) ) or
709
721
methodCall .getKeywordArgument ( "action" ) .getConstantValue ( ) .isStringlikeValue ( result ) or
710
722
result =
711
723
extractAction ( methodCall
0 commit comments