Skip to content

Commit abe4eaa

Browse files
committed
Remove deprecated Faker.Builder#config fun
resolves #80
1 parent 15bc80d commit abe4eaa

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

core/src/main/kotlin/io/github/serpro69/kfaker/Faker.kt

+24-13
Original file line numberDiff line numberDiff line change
@@ -197,24 +197,35 @@ class Faker @JvmOverloads constructor(internal val config: FakerConfig = fakerCo
197197
val zelda: Zelda = Zelda(fakerService)
198198

199199
@FakerDsl
200+
/**
201+
* DSL builder for creating instances of [Faker]
202+
*/
200203
class Builder internal constructor(){
201-
private var config = io.github.serpro69.kfaker.fakerConfig { }
204+
/**
205+
* @property config faker configuration for the [Faker] instance
206+
* which will be created with this [Faker.Builder].
207+
*/
208+
private var config: FakerConfig = io.github.serpro69.kfaker.fakerConfig { }
202209

203-
@Deprecated(
204-
message = "This API is unstable and might change in the final 1.8.0 release.",
205-
level = DeprecationLevel.WARNING,
206-
replaceWith = ReplaceWith(expression = "fakerConfig{ }")
207-
)
208-
fun config(block: FakerConfig.Builder.() -> Unit) {
210+
/**
211+
* Sets [config] configuration for this [Faker.Builder]
212+
* using the results of the [block] function.
213+
*
214+
* This [config] will then be used when an instance of [Faker] is created using this [Faker.Builder]
215+
*/
216+
fun fakerConfig(block: ConfigBuilder) {
209217
config = io.github.serpro69.kfaker.fakerConfig(block)
210218
}
211219

212-
fun fakerConfig(block: FakerConfig.Builder.() -> Unit) {
213-
config = io.github.serpro69.kfaker.fakerConfig(block)
214-
}
215-
216-
internal fun build() = Faker(config)
220+
/**
221+
* Builds an instance of [Faker] with this [config].
222+
*/
223+
internal fun build(): Faker = Faker(config)
217224
}
218225
}
219226

220-
fun faker(block: Faker.Builder.() -> Unit) = Faker.Builder().apply(block).build()
227+
/**
228+
* Applies the the [block] function to [Faker.Builder]
229+
* and returns as an instance of [Faker] from that builder.
230+
*/
231+
fun faker(block: Faker.Builder.() -> Unit): Faker = Faker.Builder().apply(block).build()

core/src/main/kotlin/io/github/serpro69/kfaker/FakerConfig.kt

+12-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,18 @@ class FakerConfig private constructor(
7272
ReplaceWith("fakerConfig { }"),
7373
level = DeprecationLevel.WARNING
7474
)
75-
fun FakerConfig.Builder.create(block: FakerConfig.Builder.() -> Unit) = this.apply(block).build()
75+
fun FakerConfig.Builder.create(block: ConfigBuilder): FakerConfig = this.apply(block).build()
7676

7777
/**
78-
* Creates an instance of [FakerConfig] with the config properties that were passed to the function [block].
78+
* Applies the the [block] function to [ConfigBuilder]
79+
* and returns as an instance of [FakerConfig] from that builder.
7980
*/
80-
fun fakerConfig(block: FakerConfig.Builder.() -> Unit) = FakerConfig.Builder().apply(block).build()
81+
fun fakerConfig(block: ConfigBuilder): FakerConfig = FakerConfig.Builder().apply(block).build()
82+
83+
/**
84+
* Lambda with [FakerConfig.Builder] receiver type that returns a [Unit].
85+
*
86+
* Used with DSL functions to construct an instance of [FakerConfig]
87+
* by applying the results of the function to the [FakerConfig.Builder].
88+
*/
89+
typealias ConfigBuilder = FakerConfig.Builder.() -> Unit

0 commit comments

Comments
 (0)