summaryrefslogtreecommitdiff
path: root/crashboxd/src/main/scala/io/crashbox/ci/yaml/CompositeReaders.scala
diff options
context:
space:
mode:
Diffstat (limited to 'crashboxd/src/main/scala/io/crashbox/ci/yaml/CompositeReaders.scala')
-rw-r--r--crashboxd/src/main/scala/io/crashbox/ci/yaml/CompositeReaders.scala29
1 files changed, 29 insertions, 0 deletions
diff --git a/crashboxd/src/main/scala/io/crashbox/ci/yaml/CompositeReaders.scala b/crashboxd/src/main/scala/io/crashbox/ci/yaml/CompositeReaders.scala
new file mode 100644
index 0000000..4df72e1
--- /dev/null
+++ b/crashboxd/src/main/scala/io/crashbox/ci/yaml/CompositeReaders.scala
@@ -0,0 +1,29 @@
+package io.crashbox.ci
+package yaml
+
+trait CompositeReaders {
+
+ implicit def mapReader[V: YamlReader] = new YamlReader[Map[String, V]] {
+ override def read(yml: YamlValue) = yml match {
+ case YamlMap(m) =>
+ m.map {
+ case (key, value) =>
+ key -> value.convertTo[V]
+ }
+ case YamlString.Empty => Map.empty[String, V]
+ case _ => formatError(yml, "mapping")
+ }
+ }
+
+ implicit def seqReader[A: YamlReader] = new YamlReader[Seq[A]] {
+ override def read(yml: YamlValue) = yml match {
+ case YamlSeq(elements) =>
+ elements.map { v =>
+ v.convertTo[A]
+ }
+ case YamlString.Empty => Seq.empty[A]
+ case _ => formatError(yml, "sequence")
+ }
+ }
+
+}