-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rework boatConfig to support configs of type Config/JsonNode
- Loading branch information
Showing
15 changed files
with
144 additions
and
80 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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import std/[parsecfg, json] | ||
|
||
import fileManager, boatConstants | ||
|
||
type BoatConfig*[T: BoatConfigKind = Config] = ref object of RootObj | ||
## base type for all boat configs | ||
use*: string ## \ | ||
## filepath, dir containing a file or remote uri | ||
|
||
parsed: T ## \ | ||
## the parsed config after loading | ||
parsedPath: string ## \ | ||
## path on disk the parsed config was saved to | ||
|
||
proc `parsed=`*(self: BoatConfig, path: string): void = | ||
self.parsed = self.parsed.retrieve path | ||
|
||
proc `parsed`*(self: BoatConfig): BoatConfigKind = self.parsed | ||
|
||
proc `parsedPath=`*(self: BoatConfig, path: string): void = | ||
self.parsedPath = path | ||
|
||
proc `parsedPath`*(self: BoatConfig): string = self.parsedPath | ||
|
||
proc usePath*(self: BoatConfig, path: string): string = | ||
if path.len is Positive: path else: self.use |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from ../../../bdd import tddError | ||
|
||
import std/[ | ||
asyncdispatch, | ||
json, | ||
parsecfg, | ||
] | ||
|
||
import boatErrors, boatConstants | ||
|
||
|
||
proc persist*[T: string | Config](self: T, path: string): Future[void] {.async.} = | ||
## writes strings to path | ||
## calls parsecfg.writeConfig for configs | ||
raise tddError | ||
# lock | ||
# of string -> data.write path | ||
# of Config -> parsecfg.writeConfig path | ||
# unlock | ||
# throw if any errors occur | ||
|
||
proc retrieve*[T: BoatConfigKind](self: T, path: string): T = | ||
# retrieves a Config or Json from a path | ||
try: | ||
if self is Config: result = loadConfig path | ||
elif self is JsonNode: raise tddError # should load json from path | ||
else: raise boatConfigKindError | ||
except CatchableError: | ||
debugEcho repr getCurrentException() | ||
raise fileLoadDefect | ||
|
||
|
||
export asyncdispatch, json, parsecfg |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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