Q:

How to make configslurper delegate method call to caller class

I want to create a groovy class og script like this:
//...
def slurper = new ConfigSlurper().parse(someFile)
//...
//The exact method declaration
def methodCall(def arg){
   //Whatever i want to do
}
//Maybe it is easier with methodMissing
def methodMissing(def args) {
   //Whatever i want to do
}

The file to slurp could look like this:
some {
   property = methodCall("with arg")
}

The question is how i can delegate the "methodCall" to the class or script that parses with the configslurper? At the moment it will give you a methodMissing.

A:

Thanks to Sérgio Michels link I found a solution:
public class ScriptWithMethods extends Script {

   String scriptText;

   public ScriptWithMethods(File file) {
      scriptText = file.text
   }

   public void run() {
      GroovyShell shell = new GroovyShell();
      Closure closure = shell.evaluate("{it->$string}");
      closure.resolveStrategy = Closure.DELEGATE_FIRST
      closure.delegate = this
      closure.call()
   }

   def methodCall(def arg){
      //Whatever i want to do
   }
}

//...
def script = new ScriptWithMethods(scriptText:someFile)
def slurper = new ConfigSlurper().parse(script)

Of cause you could also use "method missing", but this works in my usecase

