This repository was archived by the owner on Aug 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Runnables
JeremySkinner edited this page Sep 13, 2010
·
4 revisions
Runnables are classes that implement the IRunnable interface. This interface defines one method, Run, which will be invoked as soon as you instantiate the class.
For example, Phantom’s MSBuild Integration is implemented as a Runnable. This means that when you make a call to ‘msbuild’ like this:
msbuild(file: "foo.sln")
…this is actually the shorthand equivalent of the following:
runnable = msbuild() runnable.file = "foo.sln" runnable.Run()
Runnables can also be used with the With Syntax. This is useful if you have lots of arguments that need to be specified. For example, the following is quite unreadable:
ncover(toolPath: "c:/program files (x86)/NCover/NCover.console.exe", reportDirectory: "build/Coverage", workingDirectory: "src/Phantom.Tests/bin/Release", applicationAssemblies: app_assemblies, program: nunit_exe, testAssembly: "Phantom.Tests.dll")
…but could be re-written as:
with ncover(): .toolPath = "c:/program files (x86)/NCover/NCover.console.exe" .reportDirectory = "build/Coverage" .workingDirectory = "src/Phantom.Tests/bin/Release" .applicationAssemblies = app_assemblies .program = nunit_exe .testAssembly = "Phantom.Tests.dll"
…and the run method will automatically be called at the end of the with block.