Config list delegates
This commit is contained in:
parent
3cf62bb6b2
commit
459e570437
@ -75,7 +75,7 @@ class NodeDescriptor(override val config: Config) : Specific {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
var tags: List<String> by value().map { value ->
|
||||
var tags: List<String> by value{ value ->
|
||||
value?.list?.map { it.string } ?: emptyList()
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package hep.dataforge.meta
|
||||
|
||||
import hep.dataforge.values.Null
|
||||
import hep.dataforge.values.Value
|
||||
import kotlin.jvm.JvmName
|
||||
|
||||
@ -10,9 +9,18 @@ import kotlin.jvm.JvmName
|
||||
/**
|
||||
* A property delegate that uses custom key
|
||||
*/
|
||||
fun Configurable.value(default: Any = Null, key: String? = null) =
|
||||
fun <T> Configurable.value(default: T, key: String? = null) =
|
||||
MutableValueDelegate(config, key, Value.of(default))
|
||||
|
||||
fun <T> Configurable.value(default: T? = null, key: String? = null, transform: (Value?) -> T) =
|
||||
MutableValueDelegate(config, key, Value.of(default)).transform(reader = transform)
|
||||
|
||||
fun Configurable.stringList(key: String? = null) =
|
||||
value { it?.list?.map { value -> value.string } ?: emptyList() }
|
||||
|
||||
fun Configurable.numberList(key: String? = null) =
|
||||
value { it?.list?.map { value -> value.number } ?: emptyList() }
|
||||
|
||||
fun Configurable.string(default: String? = null, key: String? = null) =
|
||||
MutableStringDelegate(config, key, default)
|
||||
|
||||
@ -93,6 +101,8 @@ fun Configurable.float(default: Float, key: String? = null) =
|
||||
inline fun <reified E : Enum<E>> Configurable.enum(default: E, key: String? = null) =
|
||||
MutableSafeEnumvDelegate(config, key, default) { enumValueOf(it) }
|
||||
|
||||
/* Node delegates */
|
||||
|
||||
fun Configurable.node(key: String? = null) = MutableNodeDelegate(config, key)
|
||||
|
||||
fun <T : Specific> Configurable.spec(spec: Specification<T>, key: String? = null) =
|
||||
|
@ -184,7 +184,7 @@ class MutableValueDelegate<M : MutableMeta<M>>(
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> map(writer: (T) -> Value? = { Value.of(it) }, reader: (Value?) -> T) =
|
||||
fun <T> transform(writer: (T) -> Value? = { Value.of(it) }, reader: (Value?) -> T) =
|
||||
ReadWriteDelegateWrapper(this, reader, writer)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user