Skip to content

Instantly share code, notes, and snippets.

@DrewEaster
Last active August 29, 2015 14:15
Show Gist options
  • Save DrewEaster/61b350caec733e3bcf2f to your computer and use it in GitHub Desktop.
Save DrewEaster/61b350caec733e3bcf2f to your computer and use it in GitHub Desktop.
// Provided by AmazingMongoFramework
case class MongoConfig(hostname: String, port: Int)
case class MongoConfigBuilder(hostname: Option[String] = Some("localhost"), port: Option[Int] = Some(27017)) {
def withHostname(hostname: String) = copy(hostname = Some(hostname))
def withPort(port: Int) = copy(port = Some(port))
def build() = {
// do some validation here..
MongoConfig(hostname.get, port.get)
}
}
class AmazingMongoFramework(config: MongoConfig)
// My application (example usage)
class MyApplication(config: Properties) {
val framework = new AmazingMongoFramework(
MongoConfigBuilder()
.withHostname(config.getProperty("mongo.host"))
.withPort(config.getProperty("mongo.port").toInt)
.build())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment