Skip to content
This repository was archived by the owner on May 8, 2024. It is now read-only.

Commit 51aeddb

Browse files
fix: remove business logic from object to a private function, because the result from a object was not been updated (it was a constant - JVM static) (#17)
Signed-off-by: Matheus Ferreira <matheus.ferreira@zup.com.br> Signed-off-by: Matheus Ferreira <matheus.ferreira@zup.com.br>
1 parent 003adc2 commit 51aeddb

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/main/kotlin/com/stackspot/constants/Constants.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,5 @@ object Constants {
3838
val USER_HOME: Path = Path(System.getProperty("user.home"))
3939
val STK_HOME: Path = USER_HOME.resolve(".stk")
4040
val STK_BIN: Path = STK_HOME.resolve("bin")
41-
val STACKS_DIR: Path = if (STK_HOME.resolve("stacks").exists()) {
42-
STK_HOME.resolve("stacks")
43-
} else {
44-
STK_HOME.resolve("plugins")
45-
}
4641
}
4742
}

src/main/kotlin/com/stackspot/model/ImportedStacks.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ package com.stackspot.model
1818

1919
import com.stackspot.constants.Constants
2020
import com.stackspot.yaml.parseStackYaml
21+
import java.nio.file.Path
22+
import kotlin.io.path.exists
2123

2224
class ImportedStacks {
2325

2426
fun list(): List<Stack> {
25-
val stacksDir = Constants.Paths.STACKS_DIR.toFile()
27+
val stacksDir = getStacksDirPath().toFile()
2628
return stacksDir.walk().filter {
2729
it.isDirectory
2830
}.mapNotNull {
@@ -35,4 +37,15 @@ class ImportedStacks {
3537
fun getByName(name: String): Stack? {
3638
return list().firstOrNull { it.name == name }
3739
}
40+
41+
private fun getStacksDirPath(): Path {
42+
val stkHome = Constants.Paths.STK_HOME
43+
val stacks = stkHome.resolve("stacks")
44+
val stackDir: Path = if (stacks.exists()) {
45+
stacks
46+
} else {
47+
stkHome.resolve("plugins")
48+
}
49+
return stackDir
50+
}
3851
}

0 commit comments

Comments
 (0)