Skip to content
paradigmatic edited this page Jan 5, 2013 · 6 revisions

YAML export and import facilities are provided by the module configrity-yaml. To install it using SBT, you should check that both the following dependencies are in your build configuration:

"org.streum" %% "configrity-core" % "1.0.0"

"org.streum" %% "configrity-yaml" % "1.0.0"

This module depends on the excellent Java library snakeyaml which will be installed automatically by SBT.

Usage

The YAML module provides a new format for import/export. You can pass this format as an optional argument to the methods Configuration.load(...), Configuration.loadResource(...) and Configuration#save(...). For example:

import org.streum.configrity._
import org.streum.configrity.yaml._

val config = Configuration.load( "before.yml", YAMLFormat )
config.set("name","Gina").save( "after.yml", YAMLFormat )

Format

YAMLFormat accepts any YAML file with the following restrictions:

  • The first level must be a map
  • Map values can be:
    • Scalars (number, strings, etc.)
    • Lists
    • Maps
  • Lists elements must be scalars.
  • When several YAML documents are included in a file, only the first one is parsed.

Example

The following YAML file:

site:
  url: http://www.example.com/3
  credentials:
    username: bob
    password: "b0b rul3z !!!"

upload:
  retrying: on
  retrying:
    times: 3

default:
  tags: [ "statistical mechanics", "physics"  ]
  latex-packages:
    - amsmath
    - fancybox
    - pstricks

is valid and is read as the configuration:

site {
  url = http://www.example.com/3
  credentials {
    username = bob
    password = b0b rul3z !!!
  }
}
default {
  tags = ["statistical mechanics","physics"]
  latex-packages = ["amsmath","fancybox","pstricks"]
}
upload {
  retrying {
    times = 3
  }
}
Clone this wiki locally