/
BundleWriter.scala
31 lines (26 loc) · 1.11 KB
/
BundleWriter.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package ml.combust.bundle
import ml.combust.bundle.dsl.Bundle
import ml.combust.bundle.serializer.{BundleSerializer, SerializationFormat}
import scala.util.Try
/**
* Created by hollinwilkins on 12/24/16.
*/
case class BundleWriter[Context <: HasBundleRegistry,
Transformer <: AnyRef](root: Transformer,
name: Option[String] = None,
format: SerializationFormat = SerializationFormat.Json,
meta: Option[ml.bundle.Attributes] = None) {
def name(value: String): BundleWriter[Context, Transformer] = copy(name = Some(value))
def format(value: SerializationFormat): BundleWriter[Context, Transformer] = copy(format = value)
def meta(value: ml.bundle.Attributes): BundleWriter[Context, Transformer] = copy(meta = Some(value))
def save(file: BundleFile)
(implicit context: Context): Try[Bundle[Transformer]] = {
val n = name.getOrElse {
context.bundleRegistry.opForObj[Any, Any, Any](root).name(root)
}
BundleSerializer(context, file).write(Bundle(name = n,
format = format,
root = root,
meta = meta))
}
}