io.fintrospect.templating.CachingClasspathViews.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fintrospect_2.10 Show documentation
Show all versions of fintrospect_2.10 Show documentation
Library that adds self-documentation to Finagle server endpoint services
package io.fintrospect.templating
import java.util.concurrent.ConcurrentHashMap
import scala.collection.JavaConverters._
import scala.io.Source.fromInputStream
class CachingClasspathViews[X](fn: String => X, suffix: String) {
private val classToTemplate = new ConcurrentHashMap[Class[_], X]().asScala
def loadView[T <: View](view: T): X = classToTemplate.getOrElseUpdate(view.getClass,
Option(getClass.getResourceAsStream("/" + view.template + suffix))
.map(fromInputStream)
.map(t => fn(t.mkString))
.getOrElse({
throw new ViewNotFound(view)
})
)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy