Skip to content

Commit

Permalink
#15 Remove option attribute transformation method
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Jun 12, 2017
1 parent b42e888 commit e7a02f7
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions app/org/elastic4play/models/Attributes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,11 @@ case class ObjectAttributeFormat(subAttributes: Seq[Attribute[_]]) extends Attri
value match {
case obj: JsObject if subNames.isEmpty
obj.fields.validatedBy {
case (name, v)
case (_name, v)
subAttributes
.find(_.name == name)
.find(_.name == _name)
.map(_.validateForUpdate(subNames, v))
.getOrElse(Bad(One(UnknownAttributeError(name, v))))
.getOrElse(Bad(One(UnknownAttributeError(_name, v))))
}
.map { _ obj }
case _ Bad(One(InvalidFormatAttributeError("", name, JsonInputValue(value))))
Expand Down Expand Up @@ -519,9 +519,8 @@ case class MultiAttributeFormat[T](attributeFormat: AttributeFormat[T]) extends
override def elasticType(attributeName: String): TypedFieldDefinition = attributeFormat.elasticType(attributeName)
}

case class OptionalAttributeFormat[T](attributeFormat: AttributeFormat[T]) extends AttributeFormat[Option[T]](attributeFormat.name)(optionFormat(attributeFormat.jsFormat)) { //}(Format(Reads.seq(attributeFormat.jsFormat), Writes.seq(attributeFormat.jsFormat))) {
case class OptionalAttributeFormat[T](attributeFormat: AttributeFormat[T]) extends AttributeFormat[Option[T]]("optional-" + attributeFormat.name)(optionFormat(attributeFormat.jsFormat)) {
override def checkJson(subNames: Seq[String], value: JsValue): Or[JsValue, Every[AttributeError]] = value match {
//case _ if !subNames.isEmpty => Bad(One(InvalidFormatAttributeError("", name, JsonInputValue(value))))
case JsNull if subNames.isEmpty Good(value)
case _ attributeFormat.checkJson(subNames, value)
}
Expand Down Expand Up @@ -577,15 +576,6 @@ 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 e7a02f7

Please sign in to comment.