
io.k8s.api.networking.v1beta1.ParentReference.scala Maven / Gradle / Ivy
package io.k8s.api.networking.v1beta1
import dev.hnaderi.k8s.utils._
/** ParentReference describes a reference to a parent object. */
final case class ParentReference(
name : String,
resource : String,
group : Option[String] = None,
namespace : Option[String] = None
) {
/** Returns a new data with name set to new value */
def withName(value: String) : ParentReference = copy(name = value)
/** transforms name to result of function */
def mapName(f: String => String) : ParentReference = copy(name = f(name))
/** Returns a new data with resource set to new value */
def withResource(value: String) : ParentReference = copy(resource = value)
/** transforms resource to result of function */
def mapResource(f: String => String) : ParentReference = copy(resource = f(resource))
/** Returns a new data with group set to new value */
def withGroup(value: String) : ParentReference = copy(group = Some(value))
/** if group has a value, transforms to the result of function*/
def mapGroup(f: String => String) : ParentReference = copy(group = group.map(f))
/** Returns a new data with namespace set to new value */
def withNamespace(value: String) : ParentReference = copy(namespace = Some(value))
/** if namespace has a value, transforms to the result of function*/
def mapNamespace(f: String => String) : ParentReference = copy(namespace = namespace.map(f))
}
object ParentReference {
implicit val encoder : Encoder[io.k8s.api.networking.v1beta1.ParentReference] = new Encoder[io.k8s.api.networking.v1beta1.ParentReference] {
def apply[T : Builder](o: io.k8s.api.networking.v1beta1.ParentReference) : T = {
val obj = ObjectWriter[T]()
obj
.write("name", o.name)
.write("resource", o.resource)
.write("group", o.group)
.write("namespace", o.namespace)
.build
}
}
implicit val decoder: Decoder[ParentReference] = new Decoder[ParentReference] {
def apply[T : Reader](t: T): Either[String, ParentReference] = for {
obj <- ObjectReader(t)
name <- obj.read[String]("name")
resource <- obj.read[String]("resource")
group <- obj.readOpt[String]("group")
namespace <- obj.readOpt[String]("namespace")
} yield ParentReference (
name = name,
resource = resource,
group = group,
namespace = namespace
)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy