All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pcimcioch.gitlabci.dsl.job.BeforeScriptDsl.kt Maven / Gradle / Ivy

There is a newer version: 1.6.0
Show newest version
package pcimcioch.gitlabci.dsl.job

import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.list
import kotlinx.serialization.builtins.serializer
import pcimcioch.gitlabci.dsl.DslBase
import pcimcioch.gitlabci.dsl.serializer.ValueSerializer

@Serializable(with = BeforeScriptDsl.BeforeScriptDslSerializer::class)
class BeforeScriptDsl : DslBase() {
    var commands: MutableList = mutableListOf()

    fun exec(command: String) = commands.add(command)
    operator fun String.unaryPlus() = [email protected](this)

    object BeforeScriptDslSerializer : ValueSerializer>(String.serializer().list, BeforeScriptDsl::commands)
    companion object {
        init {
            addSerializer(BeforeScriptDsl::class, serializer())
        }
    }
}

fun createBeforeScript(block: BeforeScriptDsl.() -> Unit = {}) = BeforeScriptDsl().apply(block)
fun createBeforeScript(vararg elements: String, block: BeforeScriptDsl.() -> Unit = {}) = createBeforeScript(elements.toList(), block)
fun createBeforeScript(elements: Iterable, block: BeforeScriptDsl.() -> Unit = {}) = BeforeScriptDsl().apply { elements.forEach { exec(it) } }.apply(block)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy