GithubHelp home page GithubHelp logo

teigen / constretto-scala Goto Github PK

View Code? Open in Web Editor NEW

This project forked from constretto/constretto-scala

0.0 1.0 0.0 1.89 MB

Scala API wrapper for Constretto

Home Page: http://constretto.org

constretto-scala's Introduction

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 loosing any of the features of Constretto.

How to Install?

Constretto is cross compiled for Scala versions 2.9.0, 2.9.0-1, 2.9.1, 2.9.2, 2.9.3 and 2.10 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.0</version>
		</dependency>
		...
	</dependencies>
	

If you are using SBT:

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

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

constretto-scala's People

Contributors

hamnis avatar kaarenilsen avatar teigen avatar zapodot avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.