Scala API wrapper for Constretto
Scala
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
project
src
.gitignore
.travis.yml
README.textile

README.textile

Constretto Scala API


Constretto Scala API is a native Scala wrapper API over the Constretto configuration management framework for Java applications.
By using this API you will be able to get a API that feels natural for Scala developers without losing any of the features of Constretto.

How to Install?

Constretto is cross compiled for Scala versions 2.10 and 2.11 and deployed to the maven central repository.

If you are using Maven, you can simply add constretto-scala as dependencies in your pom:

	<dependencies>
		...
		<dependency>
			<groupId>org.constretto</groupId>
			<artifactId>constretto-scala_${scalaVersion}</artifactId>
			<version>1.1</version>
		</dependency>
		...
	</dependencies>
	

If you are using SBT:

	val constretto = "org.constretto" %% "constretto-scala" % "1.1"

How to use?

Constretto-Scala provides a simple API to configure and retrieve values from Constretto.

	import org.constretto._
	import Constretto._
	
	val constretto = Constretto(List(properties("classpath:test.properties")),"myTag","myOtherTag")
	
	val aKeyThatMightExist:Option[String] = constretto.get[String]("myKey") 
	val aKeyThatMustExist:String = constretto[String]("myKey")  // throws exception on missing key	

Constretto-Scala defines a Converter type class for converting values to specific types.
It comes bundled with predefined instances for all ValueConverter types defined by Constretto.

	val existsInt:Option[Int] = constretto.get[Int]("someIntKey") // uses the intConverter instance to convert a string to an int
	val unknownType:Option[Bar] = constretto.get[Bar]("someBarKey") // gives compile error since no ScalaValueConverter is defined for type Bar

You can easily define your own Scala Converter instances

	object Bar {
	  implicit def barConverter = Converter.fromString[Bar] {
        _.split(":") match {
          case Array(first, second) => Bar(first, second.toInt)
        }
	  }
	}
	case class Bar(a:String, b:Int)
	
	val bar:Option[Bar] = constretto.get[Bar]("someBarKey") // compiles just fine and uses the barConverter to convert strings to Bars

How to report errors or request features?

Please use the GitHub issue tracker https://github.com/constretto/constretto-scala/issues

For further information and documentation

Constretto has several more nice features, and they are covered in the reference manual at the Constretto official website: http://constretto.org