Skip to content

Commit ad71fdb

Browse files
committed
Add missing documentation to ActionDispatch::Route
1 parent 1766916 commit ad71fdb

File tree

1 file changed

+35
-25
lines changed

1 file changed

+35
-25
lines changed

ruby/ql/lib/codeql/ruby/frameworks/ActionDispatch.qll

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ module ActionDispatch {
313313
override Location getLocation() { result = call.getLocation() }
314314
}
315315

316+
/**
317+
* A route configuration. See `Route` for more info
318+
*/
316319
newtype TRoute =
317320
/**
318321
* See `ExplicitRoute`
@@ -343,31 +346,6 @@ module ActionDispatch {
343346
*/
344347
TMatchRoute(RouteBlock b, MethodCall m) { b.getAStmt() = m and m.getMethodName() = "match" }
345348

346-
/**
347-
* Several routing methods support the keyword arguments `only:` and `except:`.
348-
* - `only:` restricts the set of actions to just those in the argument.
349-
* - `except:` removes the given actions from the set.
350-
*/
351-
bindingset[action]
352-
predicate applyActionFilters(MethodCall m, string action) {
353-
// Respect the `only` keyword argument, which restricts the set of actions.
354-
(
355-
not exists(m.getKeywordArgument("only"))
356-
or
357-
exists(Expr only | only = m.getKeywordArgument("only") |
358-
[only.(ArrayLiteral).getElement(_), only.(StringlikeLiteral)].getValueText() = action
359-
)
360-
) and
361-
// Respect the `except` keyword argument, which removes actions from the default set.
362-
(
363-
not exists(m.getKeywordArgument("except"))
364-
or
365-
exists(Expr except | except = m.getKeywordArgument("except") |
366-
[except.(ArrayLiteral).getElement(_), except.(StringlikeLiteral)].getValueText() != action
367-
)
368-
)
369-
}
370-
371349
/**
372350
* A route configuration. This defines a combination of HTTP method and URL
373351
* path which should be routed to a particular controller-action pair.
@@ -381,12 +359,19 @@ module ActionDispatch {
381359
* ```
382360
*/
383361
abstract class Route extends TRoute {
362+
/**
363+
* Gets the name of a primary CodeQL class to which this route belongs.
364+
*/
384365
string getAPrimaryQlClass() { result = "Route" }
385366

386367
MethodCall method;
387368

369+
/** Gets a string representation of this route. */
388370
string toString() { result = method.toString() }
389371

372+
/**
373+
* Gets the location of the method call that defines this route.
374+
*/
390375
Location getLocation() { result = method.getLocation() }
391376

392377
/**
@@ -713,6 +698,31 @@ module ActionDispatch {
713698
}
714699
}
715700

701+
/**
702+
* Several routing methods support the keyword arguments `only:` and `except:`.
703+
* - `only:` restricts the set of actions to just those in the argument.
704+
* - `except:` removes the given actions from the set.
705+
*/
706+
bindingset[action]
707+
predicate applyActionFilters(MethodCall m, string action) {
708+
// Respect the `only` keyword argument, which restricts the set of actions.
709+
(
710+
not exists(m.getKeywordArgument("only"))
711+
or
712+
exists(Expr only | only = m.getKeywordArgument("only") |
713+
[only.(ArrayLiteral).getElement(_), only.(StringlikeLiteral)].getValueText() = action
714+
)
715+
) and
716+
// Respect the `except` keyword argument, which removes actions from the default set.
717+
(
718+
not exists(m.getKeywordArgument("except"))
719+
or
720+
exists(Expr except | except = m.getKeywordArgument("except") |
721+
[except.(ArrayLiteral).getElement(_), except.(StringlikeLiteral)].getValueText() != action
722+
)
723+
)
724+
}
725+
716726
/**
717727
* Holds if the (resource, method, path, action) combination would be generated by a call to `resources :<resource>`.
718728
*/

0 commit comments

Comments
 (0)