Skip to content

Instantly share code, notes, and snippets.

@davegurnell
Created June 17, 2015 08:48
Show Gist options
  • Select an option

  • Save davegurnell/94fbf5087d8102167e05 to your computer and use it in GitHub Desktop.

Select an option

Save davegurnell/94fbf5087d8102167e05 to your computer and use it in GitHub Desktop.
PluginDemo.scala
trait FooPlugin {
def name: String =
// Get rid of synthetic '$'s in generated class names for singleton objects:
getClass.getSimpleName.filterNot(_ == '$')
// TODO: Insert Plugin Methods
}
object FooPlugin1 extends FooPlugin
object FooPlugin2 extends FooPlugin
object FooPlugin3 extends FooPlugin
object FooPlugin extends SomeLoggingFramework {
val all = Seq(
FooPlugin1,
FooPlugin2,
FooPlugin3)
def load(name: String): Option[FooPlugin] = {
val optPlugin = all find (_.name == name)
if(optPlugin.isEmpty) {
logger.warn(s"HealthCheck plugin not found: $name")
}
optPlugin
}
def loadAll(names: Seq[String]): Seq[FooPlugin] =
names flatMap load
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment