Permalink
Browse files

[reactivemongo] Add clause extractor `NotInClause(List(_))`.

  • Loading branch information...
cchantep
cchantep committed Oct 27, 2014
1 parent ded53ee commit 6197ee32151ccfa03f75ce6dfef563ee39c9581b
View
@@ -330,6 +330,12 @@ val queryHandler = QueryHandler { queryRequest =>
}
```
Acolyte also provides extractors for inner clauses.
- `ValueList(List[(String, BSONValue)](_))` to match with `[...]`.
- `InClause(List[(String, BSONValue)](_))` to match with `{ '$in': [...] }`.
- `NotInClause(List[(String, BSONValue)](_))` to match with `{ '$nin': [...] }`.
Pattern matching using rich syntax `~(..., ...)` requires [scalac plugin](../scalac-plugin/readme.html).
Without this plugin, such parameterized extractor need to be declared as stable identifier before `match` block:
@@ -205,6 +205,23 @@ object InClause {
}
}
/**
* Not-In clause extractor.
* (\$nin with BSONArray; e.g. { '\$nin': [ ... ] })
*/
object NotInClause {
/**
* Matches BSON property with name \$nin and a BSONArray as value,
* and extracts subvalues from the array.
*/
def unapply(bson: BSONValue): Option[List[BSONValue]] =
bson match {
case ValueDocument(("$nin", a @ BSONArray(_)) :: _)
Some(a.values.toList)
case _ None
}
}
/**
* Meta-extractor, to combine extractor on BSON properties.
* @see SimpleBody
@@ -337,6 +337,14 @@ object RequestSpec extends org.specs2.mutable.Specification
BSONString("A") :: BSONString("B") :: Nil)) :: Nil) ok
}
}
"be extracted from an $nin clause" in {
BSONDocument("selector" -> BSONDocument("$nin" -> BSONArray("A", "B"))).
aka("body") must beLike {
case ValueDocument(("selector", NotInClause(
BSONString("A") :: BSONString("B") :: Nil)) :: Nil) ok
}
}
}
"Multiple document body" should {

0 comments on commit 6197ee3

Please sign in to comment.