All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.k8s.api.admissionregistration.v1.MatchCondition.scala Maven / Gradle / Ivy

package io.k8s.api.admissionregistration.v1

import dev.hnaderi.k8s.utils._

/** MatchCondition represents a condition which must by fulfilled for a request to be sent to a webhook. */
final case class MatchCondition(
  expression : String,
  name : String
) {

  /** Returns a new data with expression set to new value */
  def withExpression(value: String) : MatchCondition = copy(expression = value)
  /** transforms expression to result of function */
  def mapExpression(f: String => String) : MatchCondition = copy(expression = f(expression))

  /** Returns a new data with name set to new value */
  def withName(value: String) : MatchCondition = copy(name = value)
  /** transforms name to result of function */
  def mapName(f: String => String) : MatchCondition = copy(name = f(name))
}

object MatchCondition {

    implicit val encoder : Encoder[io.k8s.api.admissionregistration.v1.MatchCondition] = new Encoder[io.k8s.api.admissionregistration.v1.MatchCondition] {
        def apply[T : Builder](o: io.k8s.api.admissionregistration.v1.MatchCondition) : T = {
          val obj = ObjectWriter[T]()
          obj
            .write("expression", o.expression)
            .write("name", o.name)
            .build
        }
    }

    implicit val decoder: Decoder[MatchCondition] = new Decoder[MatchCondition] {
      def apply[T : Reader](t: T): Either[String, MatchCondition] = for {
          obj <- ObjectReader(t)
          expression <- obj.read[String]("expression")
          name <- obj.read[String]("name")
      } yield MatchCondition (
          expression = expression,
          name = name
        )
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy