Skip to content

Commit

Permalink
Change the internal type of NextflowAuto.publish to strictly use 'Str…
Browse files Browse the repository at this point in the history
…ing'

TODO change how the nextflow layer handles the parameter
  • Loading branch information
Grifs committed Oct 9, 2023
1 parent ae8c68d commit 5ab3664
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
10 changes: 3 additions & 7 deletions src/main/scala/io/viash/platforms/nextflow/NextflowAuto.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,8 @@ case class NextflowAuto(
|Default: `false`.
|""".stripMargin)
@default("False")
publish: Either[Boolean, String] = Left(false)
publish: Either[Boolean, String] = Right("false")
) {
// if publish is a string, it must be "state"
val checkPublish = publish match {
case Left(value) => true
case Right(value) => value == "state"
}
assert(checkPublish, message = "publish must be either a boolean or equal to \"state\"")
assert(publish.isRight, message = "expected publish to be converted to a string")
assert(Seq("true", "false", "state").contains(publish.toOption.get), message = "publish must be either a boolean or equal to \"state\"")
}
17 changes: 16 additions & 1 deletion src/main/scala/io/viash/platforms/nextflow/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,22 @@ package object nextflow {
implicit val decodeNextflowDirectives: Decoder[NextflowDirectives] = deriveConfiguredDecoderFullChecks

implicit val encodeNextflowAuto: Encoder.AsObject[NextflowAuto] = deriveConfiguredEncoder
implicit val decodeNextflowAuto: Decoder[NextflowAuto] = deriveConfiguredDecoderFullChecks
implicit val decodeNextflowAuto: Decoder[NextflowAuto] = deriveConfiguredDecoderFullChecks[NextflowAuto].prepare(
_.withFocus(_.mapObject{ conf =>
val publish = conf.apply("publish").map {
publish =>
publish.asBoolean match {
case Some(true) => Json.fromString("true")
case Some(false) => Json.fromString("false")
case None => publish
}
}
publish match {
case Some(publish) => conf.add("publish", publish)
case None => conf
}
})
)

implicit val encodeNextflowConfig: Encoder.AsObject[NextflowConfig] = deriveConfiguredEncoder
implicit val decodeNextflowConfig: Decoder[NextflowConfig] = deriveConfiguredDecoderFullChecks
Expand Down

0 comments on commit 5ab3664

Please sign in to comment.