diff --git a/build.gradle.kts b/build.gradle.kts index 1bbfe167..1cd8b00e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -46,17 +46,19 @@ allprojects { group = "hep.dataforge" version = "0.1.2-dev-5" - - // apply bintray configuration - apply(from = "${rootProject.rootDir}/gradle/bintray.gradle") - - //apply artifactory configuration - apply(from = "${rootProject.rootDir}/gradle/artifactory.gradle") - } subprojects { + if(name.startsWith("dataforge")){ + // apply bintray configuration + apply(from = "${rootProject.rootDir}/gradle/bintray.gradle") + + //apply artifactory configuration + apply(from = "${rootProject.rootDir}/gradle/artifactory.gradle") + + } + // dokka { // outputFormat = "html" // outputDirectory = javadoc.destinationDir diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/ConfigDelegates.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/ConfigDelegates.kt index 9a5f15cb..3f39b8bf 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/ConfigDelegates.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/ConfigDelegates.kt @@ -22,9 +22,23 @@ fun Configurable.boolean(default: Boolean? = null, key: String? = null) = fun Configurable.number(default: Number? = null, key: String? = null) = MutableNumberDelegate(config, key, default) -fun Configurable.node(key: String? = null) = MutableNodeDelegate(config, key) +/* Number delegates*/ + +fun Configurable.int(default: Int? = null, key: String? = null) = + number(default, key).int + +fun Configurable.double(default: Double? = null, key: String? = null) = + number(default, key).double + +fun Configurable.long(default: Long? = null, key: String? = null) = + number(default, key).long + +fun Configurable.short(default: Short? = null, key: String? = null) = + number(default, key).short + +fun Configurable.float(default: Float? = null, key: String? = null) = + number(default, key).float -//fun Configurable.spec(spec: Specification, key: String? = null) = ChildConfigDelegate(key) { spec.wrap(this) } @JvmName("safeString") fun Configurable.string(default: String, key: String? = null) = @@ -51,5 +65,38 @@ fun Configurable.number(key: String? = null, default: () -> Number) = MutableSafeNumberDelegate(config, key, default) +/* Safe number delegates*/ + +@JvmName("safeInt") +fun Configurable.int(default: Int, key: String? = null) = + number(default, key).int + +@JvmName("safeDouble") +fun Configurable.double(default: Double, key: String? = null) = + number(default, key).double + +@JvmName("safeLong") +fun Configurable.long(default: Long, key: String? = null) = + number(default, key).long + +@JvmName("safeShort") +fun Configurable.short(default: Short, key: String? = null) = + number(default, key).short + +@JvmName("safeFloat") +fun Configurable.float(default: Float, key: String? = null) = + number(default, key).float + +/** + * Enum delegate + */ inline fun > Configurable.enum(default: E, key: String? = null) = - MutableSafeEnumvDelegate(config, key, default) { enumValueOf(it) } \ No newline at end of file + MutableSafeEnumvDelegate(config, key, default) { enumValueOf(it) } + +fun Configurable.node(key: String? = null) = MutableNodeDelegate(config, key) + +fun Configurable.spec(spec: SpecificationCompanion, key: String? = null) = + MutableMorphDelegate(config, key) { spec.wrap(it) } + +fun Configurable.spec(builder: (Config) -> T, key: String? = null) = + MutableMorphDelegate(config, key) { specification(builder).wrap(it) } \ No newline at end of file diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Specification.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Specification.kt index 44f657de..72e6e4b6 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Specification.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Specification.kt @@ -22,7 +22,7 @@ interface SpecificationCompanion { fun build(action: T.() -> Unit) = update(Config(), action) - fun empty() = build { } + fun empty() = build { } /** * Wrap generic configuration producing instance of desired type @@ -59,5 +59,4 @@ fun > S.createStyle(action: C.( fun Specification.spec( spec: SpecificationCompanion, key: String? = null -) = - MutableMorphDelegate(config, key) { spec.wrap(config) } \ No newline at end of file +) = MutableMorphDelegate(config, key) { spec.wrap(it) } \ No newline at end of file diff --git a/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MetaDelegateTest.kt b/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MetaDelegateTest.kt index fbd93e62..34cb43b6 100644 --- a/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MetaDelegateTest.kt +++ b/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MetaDelegateTest.kt @@ -12,17 +12,30 @@ class MetaDelegateTest { @Test fun delegateTest() { + + class InnerSpec(override val config: Config) : Specification { + var innerValue by string() + } + + val innerSpec = specification(::InnerSpec) + val testObject = object : Specification { override val config: Config = Config() - var myValue by config.string() - var safeValue by config.number(2.2) + var myValue by string() + var safeValue by double(2.2) var enumValue by config.enum(TestEnum.YES) + var inner by spec(innerSpec) } testObject.config["myValue"] = "theString" testObject.enumValue = TestEnum.NO + + testObject.inner = innerSpec.build { innerValue = "ddd"} + assertEquals("theString", testObject.myValue) assertEquals(TestEnum.NO, testObject.enumValue) assertEquals(2.2, testObject.safeValue) + assertEquals("ddd", testObject.inner?.innerValue) + } } \ No newline at end of file