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 * Filter data using [DataFilter] builder
*/ */
fun <T : Any> DataNode<T>.filter(filterBuilder: DataFilter.() -> Unit): DataNode<T> = 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 * Add a value descriptor using block for
*/ */
fun value(name: String, block: ValueDescriptor.() -> Unit) { 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) { 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 val items: Map<String, ItemDescriptor> get() = nodes + values
@ -205,8 +205,7 @@ class ValueDescriptor(config: Config) : ItemDescriptor(config) {
override fun wrap(config: Config): ValueDescriptor = ValueDescriptor(config) override fun wrap(config: Config): ValueDescriptor = ValueDescriptor(config)
inline fun <reified E : Enum<E>> enum(name: String) = inline fun <reified E : Enum<E>> enum(name: String) = ValueDescriptor {
build {
this.name = name this.name = name
type(ValueType.STRING) type(ValueType.STRING)
this.allowedValues = enumValues<E>().map { Value.of(it.name) } this.allowedValues = enumValues<E>().map { Value.of(it.name) }

View File

@ -25,9 +25,9 @@ interface Specification<T : Specific> {
return wrap(config).apply(action) 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 * Wrap generic configuration producing instance of desired type

View File

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

View File

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

View File

@ -15,7 +15,7 @@ class SpecificationTest {
@Test @Test
fun testSpecific(){ fun testSpecific(){
val testObject = TestSpecific.build { val testObject = TestSpecific {
list = emptyList() list = emptyList()
} }
assertEquals(emptyList(), testObject.list) 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 * Use DSL to create a descriptor for this task
*/ */
fun description(transform: NodeDescriptor.() -> Unit) { fun description(transform: NodeDescriptor.() -> Unit) {
this.descriptor = NodeDescriptor.build(transform) this.descriptor = NodeDescriptor(transform)
} }
internal fun build(): GenericTask<R> { internal fun build(): GenericTask<R> {

View File

@ -105,7 +105,7 @@ fun <T : Any> TaskDependencyContainer.dependsOn(
* Add custom data dependency * Add custom data dependency
*/ */
fun TaskDependencyContainer.data(action: DataFilter.() -> Unit): DataDependency = 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 * User-friendly way to add data dependency