Skip to content

Commit

Permalink
#15 Add method to transform an attribute to optional attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Jun 9, 2017
1 parent 0000324 commit b42e888
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/org/elastic4play/models/Attributes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ object AttachmentAttributeFormat extends AttributeFormat[Attachment]("attachment
}
}

override def fromInputValue(subNames: Seq[String], value: InputValue): Attachment Or Every[AttributeError] = sys.error("not implemented")
override def fromInputValue(subNames: Seq[String], value: InputValue): Attachment Or Every[AttributeError] =
Bad(One(InvalidFormatAttributeError("", name, value)))

override def elasticToJson(values: Seq[Any]): Option[JsValue] = values match {
case Seq(m: util.Map[_, _])
Expand Down Expand Up @@ -576,6 +577,15 @@ case class Attribute[T](
description: String) {
def defaultValueJson: Option[JsValue] = defaultValue.map(d format.jsFormat.writes(d()))

def toOptional: Attribute[Option[T]] =
Attribute[Option[T]](
modelName,
name,
OptionalAttributeFormat(format),
options,
defaultValue.map(a () Some(a())),
description)

lazy val isMulti: Boolean = format match {
case _: MultiAttributeFormat[_] true
case _ false
Expand Down

0 comments on commit b42e888

Please sign in to comment.