mirror of https://github.com/sbt/sbt.git
hierarchical in-memory settings
This commit is contained in:
parent
0c12c5e2bd
commit
b03b56ea2e
|
|
@ -0,0 +1,29 @@
|
||||||
|
package sbt
|
||||||
|
|
||||||
|
sealed trait Settings
|
||||||
|
{
|
||||||
|
def get[T](key: AttributeKey[T], path: List[String]): Option[T]
|
||||||
|
def set[T](key: AttributeKey[T], path: List[String], value: T): Settings
|
||||||
|
}
|
||||||
|
object Settings
|
||||||
|
{
|
||||||
|
def empty: Settings = new Basic(Map.empty)
|
||||||
|
def x = 3
|
||||||
|
|
||||||
|
private[this] class Basic(val roots: Map[ List[String], AttributeMap ]) extends Settings
|
||||||
|
{
|
||||||
|
def get[T](key: AttributeKey[T], path: List[String]): Option[T] =
|
||||||
|
{
|
||||||
|
def notFound = path match {
|
||||||
|
case Nil => None
|
||||||
|
case x :: xs => get(key, xs)
|
||||||
|
}
|
||||||
|
(roots get path) flatMap ( _ get key ) orElse notFound
|
||||||
|
}
|
||||||
|
def set[T](key: AttributeKey[T], path: List[String], value: T): Settings =
|
||||||
|
{
|
||||||
|
val amap = (roots get path) getOrElse AttributeMap.empty
|
||||||
|
new Basic( roots updated(path, amap put(key, value)) )
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue