-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename SpecmaticConfigFactory to VersionAwareConfigParser and moved c…
…urrent implementation to extension functions
- Loading branch information
1 parent
579d903
commit 1d861cd
Showing
5 changed files
with
32 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
core/src/main/kotlin/io/specmatic/core/config/SpecmaticConfigFactory.kt
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
core/src/main/kotlin/io/specmatic/core/config/VersionAwareConfigParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.specmatic.core.config | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory | ||
import com.fasterxml.jackson.module.kotlin.registerKotlinModule | ||
import io.specmatic.core.SpecmaticConfig | ||
import io.specmatic.core.config.v1.SpecmaticConfigV1 | ||
import io.specmatic.core.config.v2.SpecmaticConfigV2 | ||
import java.io.File | ||
|
||
private const val SPECMATIC_CONFIG_VERSION = "version" | ||
|
||
private val objectMapper = ObjectMapper(YAMLFactory()).registerKotlinModule() | ||
|
||
fun File.toSpecmaticConfig(): SpecmaticConfig { | ||
val configYaml = this.readText() | ||
return when (configYaml.getVersion()) { | ||
2 -> objectMapper.readValue(configYaml, SpecmaticConfigV2::class.java).transform() | ||
else -> objectMapper.readValue(configYaml, SpecmaticConfigV1::class.java).transform() | ||
} | ||
} | ||
|
||
private fun String.getVersion(): Int? { | ||
return objectMapper.readTree(this).get(SPECMATIC_CONFIG_VERSION)?.intValue() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters