feat: add YmlConfigWrapper for managing YAML configuration files#169
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a convenient wrapper class for managing YAML-based configuration files using the existing Sponge configuration infrastructure. The YmlConfigWrapper provides a simplified, type-safe API for loading, editing, and saving configuration objects, along with an extension function for easy instantiation.
Key changes:
- Added
YmlConfigWrapper<T>class providing a high-level API for YAML config management with built-in reload and edit capabilities - Introduced
SurfConfigApi.createYmlConfig()extension function as a convenient factory method using reified generics - Bumped plugin version from 1.6.4 to 1.6.5
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/config/YmlConfigWrapper.kt | Introduces the new YmlConfigWrapper class and createYmlConfig extension function for simplified YAML configuration management |
| surf-api-gradle-plugin/build.gradle.kts | Updates plugin version from 1.6.4 to 1.6.5 to reflect the new configuration wrapper feature |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…surfapi/core/api/config/YmlConfigWrapper.kt Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…surfapi/core/api/config/YmlConfigWrapper.kt Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…o feat/add-yml-config-wrapper
- Removed `YmlConfigWrapper` class, including its constructor and methods for YAML configuration handling. - Deleted `createYmlConfig` extension function from `SurfConfigApi`.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| override val manager = | ||
| surfConfigApi.createSpongeJsonConfigManager(configClass, configFolder, fileName) |
There was a problem hiding this comment.
Property initialization order issue: manager is initialized before subclass properties. The manager property initialization accesses configFolder and fileName, which are abstract properties that won't be initialized until after the superclass constructor completes. This will cause a runtime error.
Consider making manager a lazy property or use a different initialization pattern:
override val manager by lazy {
surfConfigApi.createSpongeJsonConfigManager(configClass, configFolder, fileName)
}| override val manager = | |
| surfConfigApi.createSpongeJsonConfigManager(configClass, configFolder, fileName) | |
| override val manager by lazy { | |
| surfConfigApi.createSpongeJsonConfigManager(configClass, configFolder, fileName) | |
| } |
| inline fun edit(save: Boolean = true, block: C.() -> Unit) { | ||
| config.block() | ||
| if (save) { | ||
| save() | ||
| } | ||
| } |
There was a problem hiding this comment.
The edit method lacks synchronization, which could lead to race conditions if multiple threads modify the configuration concurrently. Consider adding synchronization to ensure thread-safe access:
@Synchronized
inline fun edit(save: Boolean = true, block: C.() -> Unit) {
config.block()
if (save) {
save()
}
}Note: This should align with thread-safety patterns used elsewhere in SpongeConfigManager (e.g., in save() and reloadFromFile()).
| override val manager = | ||
| surfConfigApi.createSpongeYmlConfigManager(configClass, configFolder, fileName) |
There was a problem hiding this comment.
Property initialization order issue: manager is initialized before subclass properties. The manager property initialization accesses configFolder and fileName, which are abstract properties that won't be initialized until after the superclass constructor completes. This will cause a runtime error.
Consider making manager a lazy property or use a different initialization pattern:
override val manager by lazy {
surfConfigApi.createSpongeYmlConfigManager(configClass, configFolder, fileName)
}| override val manager = | |
| surfConfigApi.createSpongeYmlConfigManager(configClass, configFolder, fileName) | |
| override val manager by lazy { | |
| surfConfigApi.createSpongeYmlConfigManager(configClass, configFolder, fileName) | |
| } |
…example - Updated `SpongeYmlConfigClass` and `SpongeJsonConfigClass` constructors to accept `configFolder` and `fileName` as parameters. - Adjusted `SpongeConfigClass` to make `configFolder` and `fileName` non-abstract. - Added new `ModernTestConfig` class with example usage and randomization functionality.
This pull request introduces a new utility for managing YAML-based configuration files and bumps the plugin version. The main addition is the
YmlConfigWrapperclass, which simplifies loading, editing, and saving configuration objects using a Sponge-based manager. There's also a helper extension for easy instantiation, and the plugin version is incremented to reflect the new functionality.Configuration management improvements:
YmlConfigWrapperclass for type-safe and convenient management of YAML configuration files, including automatic loading, editing, and saving viaSpongeConfigManager. (surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/config/YmlConfigWrapper.kt)SurfConfigApi.createYmlConfiginline extension function for easy creation ofYmlConfigWrapperinstances. (surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/config/YmlConfigWrapper.kt)Versioning:
1.6.4to1.6.5to reflect new features. (surf-api-gradle-plugin/build.gradle.kts)