Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract faker's providers into several sub-modules of their own #219

Merged
merged 43 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
df07fe3
Refactor gradle build files to support multiple provider implementations
serpro69 Feb 14, 2024
eef0cd8
Add standalone provider module for books (wip)
serpro69 Feb 15, 2024
f8aac82
Fix FakerService#getProvider for standalone provider implementations
serpro69 Feb 15, 2024
3b09691
Add support for custom fake generator implementations
serpro69 Feb 15, 2024
f8f2898
Add 'games' provider module
serpro69 Feb 15, 2024
6a38128
Add 'movies' provider module
serpro69 Feb 16, 2024
1e54903
Add 'tvshows' provider module
serpro69 Feb 16, 2024
1cce7a0
Add 'music' provider module
serpro69 Feb 16, 2024
6b22101
Add 'sports' provider module
serpro69 Feb 16, 2024
9285e75
Add 'japmedia' provider module
serpro69 Feb 16, 2024
5d07f10
Add 'tech' provider module
serpro69 Feb 16, 2024
244a90b
Add 'commerce' provider module
serpro69 Feb 16, 2024
62b606f
Fix yml anchors/aliases when converting yml-to-json
serpro69 Feb 16, 2024
2f8f5f4
Move some data generators from core Faker to new modules
serpro69 Feb 17, 2024
c339092
Add 'humor' provider module
serpro69 Feb 17, 2024
144929f
Delete duplicated data generator
serpro69 Feb 17, 2024
2c9cc3b
Add 'lorem' provider module
serpro69 Feb 17, 2024
b6aa9ae
Fix kdocs for fakers' classes
serpro69 Feb 17, 2024
50b2bb6
Add 'travel' provider module
serpro69 Feb 17, 2024
f381ec4
Add 'edu' provider module
serpro69 Feb 17, 2024
ab4d1b7
Add 'misc' provider module
serpro69 Feb 17, 2024
3e559d7
Add 'creature' provider module
serpro69 Feb 17, 2024
a1981e4
Move last data generators from core Faker to new modules
serpro69 Feb 17, 2024
0255c07
Fix App#author generator
serpro69 Feb 17, 2024
b750af6
Add *FakerIT integration tests for all providers
serpro69 Feb 17, 2024
649a6cb
Update cli-bot 'list' and 'lookup' commands to use all fakers
serpro69 Feb 17, 2024
4b46c43
Add '--list-fakers' option to cli-bot 'list' command
serpro69 Feb 17, 2024
dd7dd4f
Fix cli-bot tests
serpro69 Feb 17, 2024
2c95416
Ensure providers' Test tasks depend on :core:shadowJar
serpro69 Feb 17, 2024
2d02853
Add readme to each provider module
serpro69 Feb 17, 2024
e4c6089
Rename 'provider' module to 'faker'
serpro69 Feb 18, 2024
b26dd86
Update cli-bot native image reflect-config.json
serpro69 Feb 18, 2024
4d999ad
Ensure cli-bot Test and ShadowJar tasks depend on :core:shadowJar and…
serpro69 Feb 18, 2024
6eabf89
Ensure :core:integrationTest runs after dependencies
serpro69 Feb 18, 2024
9c99f62
Ensure :cli-bot:startScripts runs after dependencies
serpro69 Feb 18, 2024
8ddc55d
Fix cli-bot native image reflect-config.json
serpro69 Feb 18, 2024
95b719e
Update contributing docs
serpro69 Feb 18, 2024
c6e051f
Move 'data-provider' docs pages to their respective subdirs
serpro69 Feb 18, 2024
3b9a5a2
Add missing providers' properties to their fakers
serpro69 Feb 18, 2024
b22760b
Update docs on creating custom data providers
serpro69 Feb 18, 2024
2990a8e
Update data-providers wiki page
serpro69 Feb 18, 2024
d2a4974
Move SlackEmoji to 'lorem'
serpro69 Feb 18, 2024
5f6247a
Rename 'creature' faker to 'creatures'
serpro69 Feb 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add 'misc' provider module
  • Loading branch information
serpro69 committed Feb 17, 2024
commit ab4d1b7fbdbdf94c42e2048b335e907ab1726e14
36 changes: 9 additions & 27 deletions core/src/main/kotlin/io/github/serpro69/kfaker/Faker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ package io.github.serpro69.kfaker
import io.github.serpro69.kfaker.provider.Address
import io.github.serpro69.kfaker.provider.Ancient
import io.github.serpro69.kfaker.provider.Animal
import io.github.serpro69.kfaker.provider.Artist
import io.github.serpro69.kfaker.provider.Bird
import io.github.serpro69.kfaker.provider.Blood
import io.github.serpro69.kfaker.provider.Cat
import io.github.serpro69.kfaker.provider.Color
import io.github.serpro69.kfaker.provider.Currency
import io.github.serpro69.kfaker.provider.CurrencySymbol
import io.github.serpro69.kfaker.provider.Demographic
import io.github.serpro69.kfaker.provider.Dog
import io.github.serpro69.kfaker.provider.DrivingLicense
import io.github.serpro69.kfaker.provider.Emotion
import io.github.serpro69.kfaker.provider.File
import io.github.serpro69.kfaker.provider.Gender
Expand All @@ -25,30 +21,28 @@ import io.github.serpro69.kfaker.provider.Horse
import io.github.serpro69.kfaker.provider.IdNumber
import io.github.serpro69.kfaker.provider.Internet
import io.github.serpro69.kfaker.provider.Measurement
import io.github.serpro69.kfaker.provider.Military
import io.github.serpro69.kfaker.provider.Money
import io.github.serpro69.kfaker.provider.Name
import io.github.serpro69.kfaker.provider.Person
import io.github.serpro69.kfaker.provider.PhoneNumber
import io.github.serpro69.kfaker.provider.Quote
import io.github.serpro69.kfaker.provider.Rajnikanth
import io.github.serpro69.kfaker.provider.Relationship
import io.github.serpro69.kfaker.provider.Separator
import io.github.serpro69.kfaker.provider.misc.CryptographyProvider
import io.github.serpro69.kfaker.provider.misc.RandomClassProvider
import io.github.serpro69.kfaker.provider.misc.RandomProvider
import io.github.serpro69.kfaker.provider.misc.StringProvider

/**
* Provides access to fake data generators.
* Provides access to 'core' fake data generators.
*
* Each category (generator) from this [Faker] is represented by a property that has the same name as the `.yml` file.
*
* @property random provides public access to the functions of [RandomService].
* @property randomProvider provides additional functionality that is not covered by other data providers
* @property random provides data-generator-like functionality for the functions of [RandomService].
* @property randomClass provides additional functionality that is not covered by other data providers
* such as [address], [name], [internet], and so on. See [RandomClassProvider] for more details.
* @property string provides functionality to generate strings from expressions/templates
* @property unique global provider for generation of unique values.
* @property string provides functionality to generate strings from expressions/templates
* @property unique global provider for generation of unique values.
*/
@Suppress("unused")
class Faker @JvmOverloads constructor(config: FakerConfig = fakerConfig { }) : AbstractFaker(config) {
Expand Down Expand Up @@ -77,28 +71,22 @@ class Faker @JvmOverloads constructor(config: FakerConfig = fakerConfig { }) : A

// creature
val animal: Animal by lazy { Animal(fakerService) }
val artist: Artist by lazy { Artist(fakerService) }

// creature
val bird: Bird by lazy { Bird(fakerService) }
val blood: Blood by lazy { Blood(fakerService) }

// creature
val cat: Cat by lazy { Cat(fakerService) }

val color: Color by lazy { Color(fakerService) }
val currency: Currency by lazy { Currency(fakerService) }

// misc
val demographic: Demographic by lazy { Demographic(fakerService) }

// creature
val dog: Dog by lazy { Dog(fakerService) }

// misc
val drivingLicense: DrivingLicense by lazy { DrivingLicense(fakerService) }

// lorem
val emotion: Emotion by lazy { Emotion(fakerService) }

val file: File by lazy { File(fakerService) }
val gender: Gender by lazy { Gender(fakerService) }

Expand All @@ -113,13 +101,10 @@ class Faker @JvmOverloads constructor(config: FakerConfig = fakerConfig { }) : A

// creature
val horse: Horse by lazy { Horse(fakerService) }

val idNumber: IdNumber by lazy { IdNumber(fakerService) }
val internet: Internet by lazy { Internet(fakerService, name) }

val measurement: Measurement by lazy { Measurement(fakerService) }

// misc
val military: Military by lazy { Military(fakerService) }
val money: Money by lazy { Money(fakerService) }
val name: Name by lazy { Name(fakerService) }
val person: Person by lazy { Person(config.random) }
Expand All @@ -131,10 +116,7 @@ class Faker @JvmOverloads constructor(config: FakerConfig = fakerConfig { }) : A
// movie
val rajnikanth: Rajnikanth by lazy { Rajnikanth(fakerService) }

// misc
val relationship: Relationship by lazy { Relationship(fakerService) }

// val source: Source by lazy { Source(fakerService) }
// TODO val source: Source by lazy { Source(fakerService) }

@FakerDsl
/**
Expand Down
4 changes: 4 additions & 0 deletions provider/misc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugins {
`faker-lib-conventions`
`faker-provider-conventions`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package io.github.serpro69.kfaker.misc

import io.github.serpro69.kfaker.AbstractFaker
import io.github.serpro69.kfaker.FakerConfig
import io.github.serpro69.kfaker.FakerDsl
import io.github.serpro69.kfaker.fakerConfig
import io.github.serpro69.kfaker.misc.provider.Artist
import io.github.serpro69.kfaker.misc.provider.Blood
import io.github.serpro69.kfaker.misc.provider.Demographic
import io.github.serpro69.kfaker.misc.provider.DrivingLicense
import io.github.serpro69.kfaker.misc.provider.Military
import io.github.serpro69.kfaker.misc.provider.Relationship
import io.github.serpro69.kfaker.Faker as CoreFaker

/**
* Typealias for the [MiscFaker]
*/
typealias Faker = MiscFaker

/**
* Provides access to fake data generators that don't belong in the [CoreFaker]
* but also don't fit into any of the existing providers.
*
* Each category (generator) from this [MiscFaker] is represented by a property
* that (usually) has the same name as the `.yml` dictionary file.
*
* @property unique global provider for generation of unique values.
*/
@Suppress("unused")
class MiscFaker @JvmOverloads constructor(config: FakerConfig = fakerConfig { }) : AbstractFaker(config) {

val artist: Artist by lazy { Artist(fakerService) }
val blood: Blood by lazy { Blood(fakerService) }
val demographic: Demographic by lazy { Demographic(fakerService) }
val drivingLicense: DrivingLicense by lazy { DrivingLicense(fakerService) }
val military: Military by lazy { Military(fakerService) }
val relationship: Relationship by lazy { Relationship(fakerService) }

@FakerDsl
/**
* DSL builder for creating instances of [Faker]
*/
class Builder internal constructor() : AbstractFaker.Builder<Faker>() {

/**
* Builds an instance of [Faker] with this [config].
*/
override fun build(): Faker = Faker(config)
}
}

/**
* Applies the [block] function to [MiscFaker.Builder]
* and returns as an instance of [MiscFaker] from that builder.
*/
fun faker(block: MiscFaker.Builder.() -> Unit): MiscFaker = MiscFaker.Builder().apply(block).build()
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.github.serpro69.kfaker.provider
package io.github.serpro69.kfaker.misc.provider

import io.github.serpro69.kfaker.*
import io.github.serpro69.kfaker.dictionary.*
import io.github.serpro69.kfaker.FakerService
import io.github.serpro69.kfaker.dictionary.YamlCategory
import io.github.serpro69.kfaker.provider.FakeDataProvider
import io.github.serpro69.kfaker.provider.YamlFakeDataProvider
import io.github.serpro69.kfaker.provider.unique.LocalUniqueDataProvider
import io.github.serpro69.kfaker.provider.unique.UniqueProviderDelegate

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.github.serpro69.kfaker.provider
package io.github.serpro69.kfaker.misc.provider

import io.github.serpro69.kfaker.*
import io.github.serpro69.kfaker.dictionary.*
import io.github.serpro69.kfaker.FakerService
import io.github.serpro69.kfaker.dictionary.YamlCategory
import io.github.serpro69.kfaker.provider.FakeDataProvider
import io.github.serpro69.kfaker.provider.YamlFakeDataProvider
import io.github.serpro69.kfaker.provider.unique.LocalUniqueDataProvider
import io.github.serpro69.kfaker.provider.unique.UniqueProviderDelegate

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.github.serpro69.kfaker.provider
package io.github.serpro69.kfaker.misc.provider

import io.github.serpro69.kfaker.*
import io.github.serpro69.kfaker.dictionary.*
import io.github.serpro69.kfaker.FakerService
import io.github.serpro69.kfaker.dictionary.YamlCategory
import io.github.serpro69.kfaker.provider.FakeDataProvider
import io.github.serpro69.kfaker.provider.YamlFakeDataProvider
import io.github.serpro69.kfaker.provider.unique.LocalUniqueDataProvider
import io.github.serpro69.kfaker.provider.unique.UniqueProviderDelegate

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.github.serpro69.kfaker.provider
package io.github.serpro69.kfaker.misc.provider

import io.github.serpro69.kfaker.*
import io.github.serpro69.kfaker.dictionary.*
import io.github.serpro69.kfaker.FakerService
import io.github.serpro69.kfaker.dictionary.YamlCategory
import io.github.serpro69.kfaker.provider.FakeDataProvider
import io.github.serpro69.kfaker.provider.YamlFakeDataProvider
import io.github.serpro69.kfaker.provider.unique.LocalUniqueDataProvider
import io.github.serpro69.kfaker.provider.unique.UniqueProviderDelegate

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.github.serpro69.kfaker.provider
package io.github.serpro69.kfaker.misc.provider

import io.github.serpro69.kfaker.*
import io.github.serpro69.kfaker.dictionary.*
import io.github.serpro69.kfaker.FakerService
import io.github.serpro69.kfaker.dictionary.YamlCategory
import io.github.serpro69.kfaker.provider.FakeDataProvider
import io.github.serpro69.kfaker.provider.YamlFakeDataProvider
import io.github.serpro69.kfaker.provider.unique.LocalUniqueDataProvider
import io.github.serpro69.kfaker.provider.unique.UniqueProviderDelegate

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.github.serpro69.kfaker.provider
package io.github.serpro69.kfaker.misc.provider

import io.github.serpro69.kfaker.*
import io.github.serpro69.kfaker.dictionary.*
import io.github.serpro69.kfaker.FakerService
import io.github.serpro69.kfaker.dictionary.YamlCategory
import io.github.serpro69.kfaker.provider.FakeDataProvider
import io.github.serpro69.kfaker.provider.YamlFakeDataProvider
import io.github.serpro69.kfaker.provider.unique.LocalUniqueDataProvider
import io.github.serpro69.kfaker.provider.unique.UniqueProviderDelegate

Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ val providers = listOf(
"humor",
"japmedia",
"lorem",
"misc",
"movies",
"music",
"sports",
Expand Down