nmerouze/katamari — pull request #15 by spinscale (2013-05-18 16:14:55+00:00)
Title: Added possibility of loading settings

Hey,

I ripped a few elasticsearch classes apart and built an own settings loader. As quite some classes got added, I didnt push it to master yet. Unfortunately we cannot use the original elasticsearch classes as they include their own serialization and abstraction mechanism. Also, I did not want to pull in such a big dependency.

Let me document a bit first, what this PR request is for. Spoken simply, you can take either a YAML file and create a `Settings` class from it.

Take this YAML config file

```
http:
max.length: 10mb
port: 8080
timeout: 1s

auth:
user: admin
pass: foo

static:
assets.deliver: off

log:
rotation: on
every: 5d
```

The `Settings` class can read this file in a `Map`, consisting key/values like `static.assets.deliver = off`.

Now the magic part is, that you can read values in a better way than just via strings using the `Settings` class. Take these examples:

```
settings.getAsString("auth.user")
// this access the same property, but you can return an own settings class
// with specific settings only
settings.getComponent("auth").getAsString("user")

// return an int with a default value
settings.getAsInt("http.port", 8080)

// bools
settings.getAsBoolean("log.rotation", false)
settings.getAsBoolean("static.assets.deliver", false)

// date
settings.getAsTimeValue("http.timeout", defaultVal).milliSeconds()

// byte sizes
settings.getAsBytesSize("http.max.length", null).bytes()
```

You can load YAML files via the classloader or from a file.