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

pl.touk.nussknacker.engine.api.namespaces.NamingStrategy.scala Maven / Gradle / Ivy

There is a newer version: 1.18.0
Show newest version
package pl.touk.nussknacker.engine.api.namespaces

import com.typesafe.config.Config
import net.ceedubs.ficus.Ficus._
import pl.touk.nussknacker.engine.api.namespaces.NamingStrategy.namespaceSeparator

final case class NamingStrategy(namespace: Option[String]) {

  private val namespacePattern = namespace.map(ns => s"^$ns$namespaceSeparator(.*)".r)

  def prepareName(name: String): String = namespace match {
    case Some(value) => s"$value$namespaceSeparator$name"
    case None        => name
  }

  def decodeName(name: String): Option[String] = namespacePattern match {
    case Some(pattern) =>
      name match {
        case pattern(originalName) => Some(originalName)
        case _                     => None
      }
    case None => Some(name)
  }

}

object NamingStrategy {
  private val namespaceSeparator = "_"
  private val namespacePath      = "namespace"

  def fromConfig(modelConfig: Config): NamingStrategy = NamingStrategy(modelConfig.getAs[String](namespacePath))

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy