Specication update
This commit is contained in:
parent
6298d741ff
commit
d23c0d3781
@ -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
|
||||
|
@ -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 <T : Configurable> Configurable.spec(spec: Specification<T>, key: String? = null) = ChildConfigDelegate<T>(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 <reified E : Enum<E>> Configurable.enum(default: E, key: String? = null) =
|
||||
MutableSafeEnumvDelegate(config, key, default) { enumValueOf(it) }
|
||||
|
||||
fun Configurable.node(key: String? = null) = MutableNodeDelegate(config, key)
|
||||
|
||||
fun <T : Specification> Configurable.spec(spec: SpecificationCompanion<T>, key: String? = null) =
|
||||
MutableMorphDelegate(config, key) { spec.wrap(it) }
|
||||
|
||||
fun <T : Specification> Configurable.spec(builder: (Config) -> T, key: String? = null) =
|
||||
MutableMorphDelegate(config, key) { specification(builder).wrap(it) }
|
@ -22,7 +22,7 @@ interface SpecificationCompanion<T : Specification> {
|
||||
|
||||
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 <C : Specification, S : SpecificationCompanion<C>> S.createStyle(action: C.(
|
||||
fun <C : Specification> Specification.spec(
|
||||
spec: SpecificationCompanion<C>,
|
||||
key: String? = null
|
||||
) =
|
||||
MutableMorphDelegate(config, key) { spec.wrap(config) }
|
||||
) = MutableMorphDelegate(config, key) { spec.wrap(it) }
|
@ -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)
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user