Created
July 25, 2014 19:32
-
-
Save hgmiguel/ada233bd9c55ac812108 to your computer and use it in GitHub Desktop.
groovy method missing pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def dynamicMethods = [ | |
| [regex:"hasPermission(.*)", method:this.&hasPermission], | |
| [regex:"create(.*)Permission", method:this.&createPermission]] | |
| def methodMissing(String name, args) { | |
| def method = dynamicMethods.find { name =~ it.regex} | |
| if(method) { | |
| def match = name =~ method.regex | |
| return method.method(match[0][1], * args) | |
| } else | |
| throw new MissingMethodException(name, PermissionService , args) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment