Replace scecification builders by invokations

This commit is contained in:
Alexander Nozik 2019-12-24 20:06:16 +03:00
parent f9ae9348e2
commit 659fded3a5
8 changed files with 17 additions and 18 deletions

View File

@ -54,4 +54,4 @@ fun <T : Any> DataNode<T>.filter(filter: Meta): DataNode<T> = filter(DataFilter.
* Filter data using [DataFilter] builder
*/
fun <T : Any> DataNode<T>.filter(filterBuilder: DataFilter.() -> Unit): DataNode<T> =
filter(DataFilter.build(filterBuilder))
filter(DataFilter.invoke(filterBuilder))

View File

@ -86,7 +86,7 @@ class NodeDescriptor(config: Config) : ItemDescriptor(config) {
* Add a value descriptor using block for
*/
fun value(name: String, block: ValueDescriptor.() -> Unit) {
value(name, ValueDescriptor.build { this.name = name }.apply(block))
value(name, ValueDescriptor { this.name = name }.apply(block))
}
/**
@ -105,7 +105,7 @@ class NodeDescriptor(config: Config) : ItemDescriptor(config) {
}
fun node(name: String, block: NodeDescriptor.() -> Unit) {
node(name, build { this.name = name }.apply(block))
node(name, invoke { this.name = name }.apply(block))
}
val items: Map<String, ItemDescriptor> get() = nodes + values
@ -205,12 +205,11 @@ class ValueDescriptor(config: Config) : ItemDescriptor(config) {
override fun wrap(config: Config): ValueDescriptor = ValueDescriptor(config)
inline fun <reified E : Enum<E>> enum(name: String) =
build {
this.name = name
type(ValueType.STRING)
this.allowedValues = enumValues<E>().map { Value.of(it.name) }
}
inline fun <reified E : Enum<E>> enum(name: String) = ValueDescriptor {
this.name = name
type(ValueType.STRING)
this.allowedValues = enumValues<E>().map { Value.of(it.name) }
}
// /**
// * Build a value descriptor from annotation

View File

@ -25,9 +25,9 @@ interface Specification<T : Specific> {
return wrap(config).apply(action)
}
fun build(action: T.() -> Unit) = update(Config(), action)
operator fun invoke(action: T.() -> Unit) = update(Config(), action)
fun empty() = build { }
fun empty() = wrap(Config())
/**
* Wrap generic configuration producing instance of desired type
@ -67,7 +67,7 @@ fun <C : Specific> Specific.spec(
key: Name? = null
): MutableMorphDelegate<Config, C> = MutableMorphDelegate(config, key) { spec.wrap(it) }
fun <T: Specific> MetaItem<*>.spec(spec: Specification<T>): T? = node?.let { spec.wrap(it)}
fun <T : Specific> MetaItem<*>.spec(spec: Specification<T>): T? = node?.let { spec.wrap(it) }
@JvmName("configSpec")
fun <T: Specific> MetaItem<Config>.spec(spec: Specification<T>): T? = node?.let { spec.wrap(it)}
fun <T : Specific> MetaItem<Config>.spec(spec: Specification<T>): T? = node?.let { spec.wrap(it) }

View File

@ -6,7 +6,7 @@ import kotlin.test.assertEquals
class DescriptorTest {
val descriptor = NodeDescriptor.build {
val descriptor = NodeDescriptor {
node("aNode") {
info = "A root demo node"
value("b") {

View File

@ -29,7 +29,7 @@ class MetaDelegateTest {
testObject.config["myValue"] = "theString"
testObject.enumValue = TestEnum.NO
testObject.inner = innerSpec.build { innerValue = "ddd"}
testObject.inner = innerSpec { innerValue = "ddd" }
assertEquals("theString", testObject.myValue)
assertEquals(TestEnum.NO, testObject.enumValue)

View File

@ -15,7 +15,7 @@ class SpecificationTest {
@Test
fun testSpecific(){
val testObject = TestSpecific.build {
val testObject = TestSpecific {
list = emptyList()
}
assertEquals(emptyList(), testObject.list)

View File

@ -201,7 +201,7 @@ class TaskBuilder<R : Any>(val name: Name, val type: KClass<out R>) {
* Use DSL to create a descriptor for this task
*/
fun description(transform: NodeDescriptor.() -> Unit) {
this.descriptor = NodeDescriptor.build(transform)
this.descriptor = NodeDescriptor(transform)
}
internal fun build(): GenericTask<R> {

View File

@ -105,7 +105,7 @@ fun <T : Any> TaskDependencyContainer.dependsOn(
* Add custom data dependency
*/
fun TaskDependencyContainer.data(action: DataFilter.() -> Unit): DataDependency =
DataDependency(DataFilter.build(action)).also { add(it) }
DataDependency(DataFilter(action)).also { add(it) }
/**
* User-friendly way to add data dependency