Skip to content

Commit

Permalink
Merge pull request #2252 from circe/private-of
Browse files Browse the repository at this point in the history
Making `of` methods on Configured Encoders/Decoders Private.
  • Loading branch information
hamnis committed Apr 16, 2024
2 parents f97d8a6 + 8cb3ce9 commit c5b0a74
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 7 deletions.
Expand Up @@ -22,7 +22,8 @@ import io.circe.{ Codec, Decoder, Encoder, HCursor, JsonObject }

trait ConfiguredCodec[A] extends Codec.AsObject[A], ConfiguredDecoder[A], ConfiguredEncoder[A]
object ConfiguredCodec:
def of[A](nme: String, decoders: => List[Decoder[?]], encoders: => List[Encoder[?]], labels: List[String])(using
private def of[A](nme: String, decoders: => List[Decoder[?]], encoders: => List[Encoder[?]], labels: List[String])(
using
conf: Configuration,
mirror: Mirror.Of[A],
defaults: Default[A]
Expand Down
Expand Up @@ -189,7 +189,7 @@ trait ConfiguredDecoder[A](using conf: Configuration) extends Decoder[A]:
}

object ConfiguredDecoder:
def of[A](nme: String, decoders: => List[Decoder[?]], labels: List[String])(using
private def of[A](nme: String, decoders: => List[Decoder[?]], labels: List[String])(using
conf: Configuration,
mirror: Mirror.Of[A],
defaults: Default[A]
Expand Down
Expand Up @@ -54,7 +54,7 @@ trait ConfiguredEncoder[A](using conf: Configuration) extends Encoder.AsObject[A
JsonObject.singleton(constructorName, json)

object ConfiguredEncoder:
def of[A](encoders: => List[Encoder[?]], labels: List[String])(using
private def of[A](encoders: => List[Encoder[?]], labels: List[String])(using
conf: Configuration,
mirror: Mirror.Of[A]
): ConfiguredEncoder[A] = mirror match
Expand Down
Expand Up @@ -21,7 +21,7 @@ import io.circe.{ Codec, Decoder, Encoder, HCursor, Json }

trait ConfiguredEnumCodec[A] extends Codec[A]
object ConfiguredEnumCodec:
def of[A](decoder: Decoder[A], encoder: Encoder[A]): ConfiguredEnumCodec[A] =
private def of[A](decoder: Decoder[A], encoder: Encoder[A]): ConfiguredEnumCodec[A] =
new ConfiguredEnumCodec[A]:
def apply(c: HCursor) = decoder(c)
def apply(a: A) = encoder(a)
Expand Down
Expand Up @@ -23,7 +23,7 @@ import io.circe.{ Decoder, DecodingFailure, HCursor }

trait ConfiguredEnumDecoder[A] extends Decoder[A]
object ConfiguredEnumDecoder:
def of[A](name: String, cases: List[A], labels: List[String])(using
private def of[A](name: String, cases: List[A], labels: List[String])(using
conf: Configuration
): ConfiguredEnumDecoder[A] = new ConfiguredEnumDecoder[A]:
private val caseOf = cases.toVector
Expand Down
Expand Up @@ -23,7 +23,9 @@ import io.circe.{ Encoder, Json }

trait ConfiguredEnumEncoder[A] extends Encoder[A]
object ConfiguredEnumEncoder:
def of[A](labels: List[String])(using conf: Configuration, mirror: Mirror.SumOf[A]): ConfiguredEnumEncoder[A] =
private def of[A](
labels: List[String]
)(using conf: Configuration, mirror: Mirror.SumOf[A]): ConfiguredEnumEncoder[A] =
new ConfiguredEnumEncoder[A]:
private val labelOf = labels.toArray.map(conf.transformConstructorNames)
def apply(a: A) = Json.fromString(labelOf(mirror.ordinal(a)))
Expand Down
Expand Up @@ -34,7 +34,7 @@ trait Default[T] extends Serializable:
case defaults: NonEmptyTuple => defaults(index).asInstanceOf[Option[Any]]

object Default:
def of[T, O <: Tuple](values: => O) = new Default[T]:
private def of[T, O <: Tuple](values: => O) = new Default[T]:
type Out = O
lazy val defaults: Out = values

Expand Down

0 comments on commit c5b0a74

Please sign in to comment.