Last active
August 29, 2015 14:15
-
-
Save DrewEaster/61b350caec733e3bcf2f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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