Skip to content

Commit 5b9601e

Browse files
committed
feat: expose the static create method of Config
1 parent 403a913 commit 5b9601e

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

app/src/main/java/com/osfans/trime/data/DataManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ object DataManager {
3535
* @return the absolute path of the compiled config file
3636
*/
3737
@JvmStatic
38-
fun resolvePath(resourceId: String): String {
38+
fun resolveDeployedResourcePath(resourceId: String): String {
3939
val defaultPath = File(stagingDir, "$resourceId.yaml")
4040
if (!defaultPath.exists()) {
4141
val fallbackPath = File(prebuiltDataDir, "$resourceId.yaml")

app/src/main/java/com/osfans/trime/data/schema/SchemaManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object SchemaManager {
2424

2525
@JvmStatic
2626
fun init(schemaId: String) {
27-
val raw = File(DataManager.resolvePath("$schemaId.schema"))
27+
val raw = File(DataManager.resolveDeployedResourcePath("$schemaId.schema"))
2828
.inputStream()
2929
.bufferedReader()
3030
.use { it.readText() }

app/src/main/java/com/osfans/trime/util/config/Config.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
package com.osfans.trime.util.config
22

3+
import com.osfans.trime.data.DataManager
34
import timber.log.Timber
45

56
/**
67
* New YAML config parser intended to replace the old one.
78
*/
89
class Config(private val data: ConfigData = ConfigData()) {
910

11+
companion object {
12+
fun create(fileName: String) = Config(
13+
ConfigData().apply {
14+
loadFromFile(DataManager.resolveDeployedResourcePath(fileName))
15+
},
16+
)
17+
}
18+
1019
fun loadFromFile(fileName: String) = data.loadFromFile(fileName)
1120

1221
fun isNull(path: String): Boolean {

0 commit comments

Comments
 (0)