diff options
author | Nick Kallen <nkallen@tallbro.local> | 2010-08-23 19:47:23 -0700 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-11-07 02:08:36 -0500 |
commit | 1bd0fb6433ace1c00a1140ba700101107d1ae424 (patch) | |
tree | 4236e639c16dc02f9b37103487305837c94231b0 /libraries | |
parent | dd94d8fd7a20cfa9d39b91f158a7ce2f697ed0e1 (diff) | |
download | cbt-1bd0fb6433ace1c00a1140ba700101107d1ae424.tar.gz cbt-1bd0fb6433ace1c00a1140ba700101107d1ae424.tar.bz2 cbt-1bd0fb6433ace1c00a1140ba700101107d1ae424.zip |
Better documentation
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/eval/Eval.scala | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/libraries/eval/Eval.scala b/libraries/eval/Eval.scala index 9de9bd4..f71f2f4 100644 --- a/libraries/eval/Eval.scala +++ b/libraries/eval/Eval.scala @@ -12,11 +12,46 @@ import scala.io.Source * It is intended to be used for application configuration (rather than Configgy, XML, YAML files, etc.) * and anything else. * - * Eval takes a file or string and generates a new scala class that has an apply method that + * Consider this example. You have the following configuration file in Config.scala: + * + * package com.mycompany + * + * trait Config { + * def myValue: Int + * def myTimeout: Duration + * def myBufferSize: StorageUnit + * } + * + * You have the following configuration file in config/Development.scala: + * + * import com.mycompany.Config + * import com.twitter.util.TimeConversions._ + * import com.twitter.util.StorageUnitConversions._ + * + * new Config { + * val myValue = 1 + * val myTimeout = 2.seconds + * val myBufferSize = 14.kilobytes + * } + * + * And finally, in Main.scala: + * + * package com.mycompany + * + * object Main { + * def main(args: Array[String]) { + * val config = Eval[Config](new File(args(0))) + * ... + * } + * } + * + * Note that in this example there is no need for any configuration format like Configgy, YAML, etc. + * + * So how does this work? Eval takes a file or string and generates a new scala class that has an apply method that * evaluates that string. The newly generated file is then compiled. All generated .scala and .class * files are stored, by default, in System.getProperty("java.io.tmpdir"). * - * After compilation, the a new class loader is created with the temporary dir as the classPath. + * After compilation, a new class loader is created with the temporary dir as the classPath. * The generated class is loaded and then apply() is called. * * This implementation is inspired by |