From abe4eaa4aa1673707719332566cb52ea746672dc Mon Sep 17 00:00:00 2001 From: Sergio Pro Date: Sun, 3 Oct 2021 18:52:38 +0200 Subject: [PATCH] Remove deprecated Faker.Builder#config fun resolves #80 --- .../kotlin/io/github/serpro69/kfaker/Faker.kt | 37 ++++++++++++------- .../io/github/serpro69/kfaker/FakerConfig.kt | 15 ++++++-- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/core/src/main/kotlin/io/github/serpro69/kfaker/Faker.kt b/core/src/main/kotlin/io/github/serpro69/kfaker/Faker.kt index 9fc15b925..862ff8ce1 100644 --- a/core/src/main/kotlin/io/github/serpro69/kfaker/Faker.kt +++ b/core/src/main/kotlin/io/github/serpro69/kfaker/Faker.kt @@ -197,24 +197,35 @@ class Faker @JvmOverloads constructor(internal val config: FakerConfig = fakerCo val zelda: Zelda = Zelda(fakerService) @FakerDsl + /** + * DSL builder for creating instances of [Faker] + */ class Builder internal constructor(){ - private var config = io.github.serpro69.kfaker.fakerConfig { } + /** + * @property config faker configuration for the [Faker] instance + * which will be created with this [Faker.Builder]. + */ + private var config: FakerConfig = io.github.serpro69.kfaker.fakerConfig { } - @Deprecated( - message = "This API is unstable and might change in the final 1.8.0 release.", - level = DeprecationLevel.WARNING, - replaceWith = ReplaceWith(expression = "fakerConfig{ }") - ) - fun config(block: FakerConfig.Builder.() -> Unit) { + /** + * Sets [config] configuration for this [Faker.Builder] + * using the results of the [block] function. + * + * This [config] will then be used when an instance of [Faker] is created using this [Faker.Builder] + */ + fun fakerConfig(block: ConfigBuilder) { config = io.github.serpro69.kfaker.fakerConfig(block) } - fun fakerConfig(block: FakerConfig.Builder.() -> Unit) { - config = io.github.serpro69.kfaker.fakerConfig(block) - } - - internal fun build() = Faker(config) + /** + * Builds an instance of [Faker] with this [config]. + */ + internal fun build(): Faker = Faker(config) } } -fun faker(block: Faker.Builder.() -> Unit) = Faker.Builder().apply(block).build() +/** + * Applies the the [block] function to [Faker.Builder] + * and returns as an instance of [Faker] from that builder. + */ +fun faker(block: Faker.Builder.() -> Unit): Faker = Faker.Builder().apply(block).build() diff --git a/core/src/main/kotlin/io/github/serpro69/kfaker/FakerConfig.kt b/core/src/main/kotlin/io/github/serpro69/kfaker/FakerConfig.kt index 79297e8f0..6f1df1af9 100644 --- a/core/src/main/kotlin/io/github/serpro69/kfaker/FakerConfig.kt +++ b/core/src/main/kotlin/io/github/serpro69/kfaker/FakerConfig.kt @@ -72,9 +72,18 @@ class FakerConfig private constructor( ReplaceWith("fakerConfig { }"), level = DeprecationLevel.WARNING ) -fun FakerConfig.Builder.create(block: FakerConfig.Builder.() -> Unit) = this.apply(block).build() +fun FakerConfig.Builder.create(block: ConfigBuilder): FakerConfig = this.apply(block).build() /** - * Creates an instance of [FakerConfig] with the config properties that were passed to the function [block]. + * Applies the the [block] function to [ConfigBuilder] + * and returns as an instance of [FakerConfig] from that builder. */ -fun fakerConfig(block: FakerConfig.Builder.() -> Unit) = FakerConfig.Builder().apply(block).build() +fun fakerConfig(block: ConfigBuilder): FakerConfig = FakerConfig.Builder().apply(block).build() + +/** + * Lambda with [FakerConfig.Builder] receiver type that returns a [Unit]. + * + * Used with DSL functions to construct an instance of [FakerConfig] + * by applying the results of the function to the [FakerConfig.Builder]. + */ +typealias ConfigBuilder = FakerConfig.Builder.() -> Unit