loader

Creates a configuration loader for the specified type using Kotlin's reified generics.

Example (Kotlin - Method Chain):

val loader: ConfigLoader<AppConfig> = Yacla.loader<AppConfig>()
.fromResource("/defaults/config.yml")
.toFile(Paths.get("config.yml"))
.parser(SnakeYamlParser())
.autoUpdateIfOutdated(true)
.withLogger(ConsoleLogger())
.load()

val config: AppConfig = loader.config

Return

a ConfigLoaderBuilder for type T.


Creates a configuration loader for the specified class.

Example (Java):

ConfigLoader<AppConfig> loader = Yacla.loader(AppConfig.class)
.fromResource("/defaults/config.yml")
.toFile(Paths.get("config.yml"))
.parser(new SnakeYamlParser())
.autoUpdateIfOutdated(true)
.withLogger(new ConsoleLogger())
.load();

AppConfig config = loader.get();

Return

a ConfigLoaderBuilder for type T.

Parameters

clazz

the target class of the configuration data.


fun <T : Any> loader(clazz: Class<T>, builder: ConfigLoaderBuilder<T>.() -> Unit): ConfigLoaderBuilder<T>

Creates and configures a loader in a DSL-style block.

Example (Kotlin DSL):

val loader = Yacla.loader<AppConfig> {
fromResource("/defaults/config.yml")
toFile(Paths.get("config.yml"))
parser(SnakeYamlParser())
autoUpdateIfOutdated(true)
withLogger(ConsoleLogger())
}.load()
//or, you can use the method chain

val config: AppConfig = loader.config

Return

the configured ConfigLoaderBuilder.

Parameters

clazz

the target class of the configuration data.

builder

lambda to customize the ConfigLoaderBuilder.


inline fun <T : Any> LoaderScope.loader(noinline block: ConfigLoaderBuilder<T>.() -> Unit): ConfigLoader<T>

Creates a config loader for the specified class within a LoaderScope, applying shared defaults.

This extension is meant for use within Yacla.withDefaults DSL blocks.

Example:

val loader = loader<MyConfig> {
fromResource("/defaults/my.yml")
toFile(Paths.get("config/my.yml"))
}

Return

the loaded ConfigLoader for the specified type T

Parameters

block

configuration lambda for customizing the ConfigLoaderBuilder