File tree 1 file changed +11
-6
lines changed
src/main/scala/dev/atedeg
1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change 1
1
package dev .atedeg
2
2
3
3
import scala .util .Try
4
-
5
4
import better .files .File
6
- import io .circe .Json
5
+ import io .circe .{ Decoder , Json }
7
6
import io .circe .generic .auto .*
8
7
import io .circe .yaml .parser
9
- import cats .implicits ._
8
+ import cats .implicits .*
10
9
11
10
final case class Selector (selector : String )
12
11
final case class Configuration (ignored : List [Selector ], tables : List [TableConfig ])
13
12
final case class TableConfig (name : String , columns : List [ColumnConfig ], rows : List [Selector ])
14
13
final case class ColumnConfig (name : String , selector : String )
15
14
16
15
object Configuration {
16
+ private val configFile = " .ubidoc"
17
17
18
18
def read (defaultLocation : File ): Either [String , Configuration ] =
19
- Try ((defaultLocation / " .unidoc " ).contentAsString).toEither.leftMap(_.toString).flatMap(parse)
19
+ Try ((defaultLocation / configFile ).contentAsString).toEither.leftMap(_.toString).flatMap(parse)
20
20
21
- private def parse (raw : String ): Either [String , Configuration ] =
21
+ def parse (raw : String ): Either [String , Configuration ] =
22
22
parser.parse(raw).toOption.flatMap(parseJson).toRight(" Can not parse configuration file" )
23
- private def parseJson (json : Json ): Option [Configuration ] = json.as[Configuration ].toOption
23
+
24
+ private def parseJson (json : Json ): Option [Configuration ] = {
25
+ implicit val decoder : Decoder [List [Selector ]] =
26
+ Decoder .decodeList(Decoder .decodeString.map(Selector (_)))
27
+ json.as[Configuration ].toOption
28
+ }
24
29
}
25
30
26
31
object Selector {
You can’t perform that action at this time.
0 commit comments