Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baybatu/4676d37dfd27d519c84dd345843a88c1 to your computer and use it in GitHub Desktop.
Save baybatu/4676d37dfd27d519c84dd345843a88c1 to your computer and use it in GitHub Desktop.
Using safe method names in 'beforeInterceptor' interceptor in Grails 2.x
class MyController {
/**
* Normally, String type method name in except part of beforeInterceptor is legal. For example:
*
* def beforeInterceptor = [action: this.&intercept, except: ['index', 'hede', 'hodo']]
*
* But this is not safe for future naming refactorings. Instead, using closure-maker
* ampersand operator(.&) before method name and then getting 'method' property to get
* method name as String is better for future safe changes.
*/
def beforeInterceptor = [action: this.&intercept, except: [this.&index.getProperty('method'),
this.&hede.getProperty('method'),
this.&hodo.getProperty('method')]]
def index() {
render "Exceptional endpoint, I am in index."
}
def hede() {
render "Exceptional endpoint, I am in hede."
}
def hodo() {
render "Exceptional endpoint, I am in hodo."
}
def helehele() {
render "Enters intercept method before coming here. Hele Hele Hele is here!.."
}
private boolean intercept() {
// Enters here before request handler method invocation and returns boolean true
// if the method is wanted to be called properly. Otherwise returns false.
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment