Skip to content

Commit

Permalink
Small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
benko-ct committed Nov 25, 2024
1 parent 5c8db69 commit 52e5e05
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ object MongoFormat {
inline private def deriveTrait[A](mirrorOfSum: Mirror.SumOf[A]): MongoFormat[A] =
new MongoFormat[A] {
private val traitMetaData = AnnotationReader.readTraitMetaData[A]
private val typeHintMap = traitMetaData.subtypes.collect {
case (name, classMeta) if classMeta.typeHint.isDefined =>
name -> classMeta.typeHint.get
}
private val typeHintMap = traitMetaData.subTypeTypeHints
private val reverseTypeHintMap = typeHintMap.map((on, n) => (n, on))
private val formatters = summonFormatters[mirrorOfSum.MirroredElemTypes]
private val names = constValueTuple[mirrorOfSum.MirroredElemLabels].productIterator.toVector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ case class TraitMetaData(
subtypes: Map[String, CaseClassMetaData]
) {
val typeDiscriminator: String = typeHintFieldRaw.map(_.value).getOrElse("type")

val subTypeTypeHints: Map[String, String] = subtypes.collect {
case (name, classMeta) if classMeta.typeHint.isDefined =>
name -> classMeta.typeHint.get
}
}

object AnnotationReader {
Expand Down

0 comments on commit 52e5e05

Please sign in to comment.