0.1.8-dev-2

This commit is contained in:
Alexander Nozik 2020-05-17 20:12:44 +03:00
parent 453a1bc755
commit fb559f4562
6 changed files with 27 additions and 8 deletions

View File

@ -1,9 +1,10 @@
plugins {
val toolsVersion = "0.4.2"
val toolsVersion = "0.5.5"
id("scientifik.mpp") version toolsVersion apply false
id("scientifik.jvm") version toolsVersion apply false
id("scientifik.publish") version toolsVersion apply false
id("org.jetbrains.dokka") version "0.10.1"
}
val dataforgeVersion by extra("0.1.8-dev-2")
@ -22,4 +23,5 @@ allprojects {
subprojects {
apply(plugin = "scientifik.publish")
apply(plugin = "org.jetbrains.dokka")
}

View File

@ -13,19 +13,19 @@ kotlin {
val commonMain by getting {
dependencies {
api(project(":dataforge-meta"))
api("io.github.microutils:kotlin-logging-common:1.7.8")
api("io.github.microutils:kotlin-logging-common:1.7.9")
}
}
val jvmMain by getting {
dependencies {
api(kotlin("reflect"))
api("io.github.microutils:kotlin-logging:1.7.8")
api("io.github.microutils:kotlin-logging:1.7.9")
api("ch.qos.logback:logback-classic:1.2.3")
}
}
val jsMain by getting {
dependencies {
api("io.github.microutils:kotlin-logging-js:1.7.8")
api("io.github.microutils:kotlin-logging-js:1.7.9")
}
}
}

View File

@ -50,6 +50,13 @@ interface Configurable : Described {
}
}
/**
* Reset the property to its default value
*/
fun Configurable.resetProperty(name: Name) {
setProperty(name, null)
}
fun Configurable.getProperty(key: String) = getProperty(key.toName())
fun Configurable.setProperty(name: Name, value: Value?) = setProperty(name, value?.let { MetaItem.ValueItem(value) })

View File

@ -201,8 +201,8 @@ fun Configurable.doubleArray(vararg doubles: Double, key: Name? = null): ReadWri
/* Node delegates */
fun Configurable.config(key: Name? = null): ReadWriteProperty<Any?, Config?> =
config.node(key)
fun Configurable.config(default: Config? = null, key: Name? = null): ReadWriteProperty<Any?, Config?> =
config.node(default,key)
fun Configurable.node(key: Name? = null): ReadWriteProperty<Any?, Meta?> = item(key).map(
reader = { it.node },

View File

@ -84,8 +84,8 @@ fun <M : MutableMeta<M>> M.boolean(default: Boolean? = null, key: Name? = null):
fun <M : MutableMeta<M>> M.number(default: Number? = null, key: Name? = null): ReadWriteProperty<Any?, Number?> =
item(default, key).transform { it.number }
inline fun <reified M : MutableMeta<M>> M.node(key: Name? = null) =
item(this, key).transform { it.node as? M }
inline fun <reified M : MutableMeta<M>> M.node(default: M? = null, key: Name? = null) =
item(default, key = key).transform { it.node as? M }
@JvmName("safeString")
fun <M : MutableMeta<M>> M.string(default: String, key: Name? = null) =

View File

@ -47,10 +47,20 @@ fun ItemDescriptor.attributes(block: Config.() -> Unit) {
(attributes ?: Config().also { this.attributes = it }).apply(block)
}
/**
* Set specific attribute in the descriptor
*/
fun ItemDescriptor.setAttribute(name: Name, value: Any?) {
attributes {
set(name, value)
}
}
/**
* Check if given item suits the descriptor
*/
fun ItemDescriptor.validateItem(item: MetaItem<*>?): Boolean {
if (item == null) return !required
return when (this) {
is ValueDescriptor -> isAllowedValue(item.value ?: return false)
is NodeDescriptor -> items.all { (key, d) ->