Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:mongodb/casbah

  • Loading branch information...
commit 31135f91654ea3841dc17f124f6c76c76dadf97d 2 parents 6fcdc29 + 8431c59
@bwmcadams bwmcadams authored
View
12 casbah-commons/src/main/scala/Implicits.scala
@@ -113,4 +113,16 @@ object ValidBSONType {
implicit object BasicDBObject extends ValidBSONType[com.mongodb.BasicDBObject]
implicit object DBObject extends ValidBSONType[com.mongodb.DBObject]
}
+
+/*
+ * Nice trick from Miles Sabin using ambiguity in implicit resolution to disallow Nothing
+ */
+sealed trait NotNothing[A]{
+ type B
+}
+
+object NotNothing {
+ implicit val nothing = new NotNothing[Nothing]{ type B = Any }
+ implicit def notNothing[A] = new NotNothing[A]{ type B = A }
+}
// vim: set ts=2 sw=2 sts=2 et:
View
14 casbah-commons/src/main/scala/MongoDBList.scala
@@ -66,11 +66,7 @@ class MongoDBList(val underlying: BasicDBList = new BasicDBList) extends Seq[Any
* @return (A)
* @throws NoSuchElementException
*/
- def as[A <: Any: Manifest](idx: Int): A = {
- require(manifest[A] != manifest[scala.Nothing],
- "Type inference failed; as[A]() requires an explicit type argument" +
- "(e.g. dbList.as[<ReturnType>](index)) to function correctly.")
-
+ def as[A : NotNothing](idx: Int): A = {
underlying.get(idx) match {
case null => throw new NoSuchElementException
case value => value.asInstanceOf[A]
@@ -78,18 +74,14 @@ class MongoDBList(val underlying: BasicDBList = new BasicDBList) extends Seq[Any
}
/** Lazy utility method to allow typing without conflicting with Map's required get() method and causing ambiguity */
- def getAs[A <: Any: Manifest](idx: Int): Option[A] = {
- require(manifest[A] != manifest[scala.Nothing],
- "Type inference failed; getAs[A]() requires an explicit type argument " +
- "(e.g. dbList.getAs[<ReturnType>](index) ) to function correctly.")
-
+ def getAs[A : NotNothing](idx: Int): Option[A] = {
underlying.get(idx) match {
case null => None
case value => Some(value.asInstanceOf[A])
}
}
- def getAsOrElse[A <: Any: Manifest](idx: Int, default: => A): A = getAs[A](idx) match {
+ def getAsOrElse[A : NotNothing](idx: Int, default: => A): A = getAs[A](idx) match {
case Some(v) => v
case None => default
}
View
17 casbah-commons/src/main/scala/MongoDBObject.scala
@@ -65,11 +65,7 @@ class MongoDBObject(val underlying: DBObject = new BasicDBObject) extends scala.
* @return (A)
* @throws NoSuchElementException
*/
- def as[A <: Any: Manifest](key: String): A = {
- require(manifest[A] != manifest[scala.Nothing],
- "Type inference failed; as[A]() requires an explicit type argument" +
- "(e.g. dbObject.as[<ReturnType>](\"someKey\") ) to function correctly.")
-
+ def as[A : NotNothing](key: String): A = {
underlying.get(key) match {
case null => default(key).asInstanceOf[A]
case value => value.asInstanceOf[A]
@@ -112,18 +108,14 @@ class MongoDBObject(val underlying: DBObject = new BasicDBObject) extends scala.
def ::(elem: (String, Any)): Seq[DBObject] = Seq(MongoDBObject(elem), this)
/** Lazy utility method to allow typing without conflicting with Map's required get() method and causing ambiguity */
- def getAs[A <: Any: Manifest](key: String): Option[A] = {
- require(manifest[A] != manifest[scala.Nothing],
- "Type inference failed; getAs[A]() requires an explicit type argument " +
- "(e.g. dbObject.getAs[<ReturnType>](\"somegetAKey\") ) to function correctly.")
-
+ def getAs[A : NotNothing](key: String): Option[A] = {
underlying.get(key) match {
case null => None
case value => Some(value.asInstanceOf[A])
}
}
- def getAsOrElse[A <: Any: Manifest](key: String, default: => A): A = getAs[A](key) match {
+ def getAsOrElse[A : NotNothing](key: String, default: => A): A = getAs[A](key) match {
case Some(v) => v
case None => default
}
@@ -134,8 +126,7 @@ class MongoDBObject(val underlying: DBObject = new BasicDBObject) extends scala.
* Your type parameter must be that of the item at the bottom of the tree you specify...
* If cast fails - it's your own fault.
*/
- def expand[A <: Any: Manifest](key: String): Option[A] = {
- require(manifest[A] != manifest[scala.Nothing], "Type inference failed; expand[A]() requires an explicit type argument (e.g. dbObject[<ReturnType](\"someKey\") ) to function correctly.")
+ def expand[A : NotNothing](key: String): Option[A] = {
@tailrec
def _dot(dbObj: MongoDBObject, key: String): Option[_] =
if (key.indexOf('.') < 0) {
View
5 casbah-commons/src/test/scala/MongoDBObjectSpec.scala
@@ -209,6 +209,9 @@ class MongoDBObjectSpec extends CasbahMutableSpecification {
dbObj.as[MongoDBList]("foo") must haveTheSameElementsAs(List("a", "b", "c"))
dbObj.as[DBObject]("bar") must haveEntry("baz" -> "foo")
dbObj.as[String]("nullValue") must throwA[NoSuchElementException]
+
+// DOES NOT COMPILE ANYMORE
+// (dbObj.as("x"):Any) must throwA[IllegalArgumentException]
}
"Support 'as' methods for casting by type" in {
@@ -221,6 +224,8 @@ class MongoDBObjectSpec extends CasbahMutableSpecification {
dbObj.getAs[Float]("omgponies") must beNone
dbObj.getAs[Double]("x").get must throwA[ClassCastException]
+// DOES NOT COMPILE ANYMORE
+// (dbObj.getAs("x"):Any) must throwA[IllegalArgumentException]
}
"as functions as expected" in {
View
30 casbah-query/src/main/scala/BarewordOperators.scala
@@ -68,8 +68,6 @@ class NestedBarewordListOperator(oper: String) {
}
-
-
/**
* Aggregation object for Bareword Operators.
* Bareword operators stand on their own - they lack the requirement for an LValue.
@@ -180,15 +178,8 @@ trait PushOp extends PushOpBase {
}
trait PushAllOpBase extends BarewordQueryOperator {
- protected def _pushAll[A <: Any: Manifest](args: (String, A)*): DBObject =
- if (manifest[A] <:< manifest[Iterable[_]])
- apply("$pushAll")(args.map(z => z._1 -> z._2.asInstanceOf[Iterable[_]]): _*)
- else if (manifest[A] <:< manifest[Product])
- apply("$pushAll")(args.map(z => z._1 -> z._2.asInstanceOf[Product].productIterator.toIterable): _*)
- else if (manifest[A].erasure.isArray)
- apply("$pushAll")(args.map(z => z._1 -> z._2.asInstanceOf[Array[_]].toIterable): _*)
- else
- throw new IllegalArgumentException("$pushAll may only be invoked with a (String, A) where String is the field name and A is an Iterable or Product/Tuple of values (got %s).".format(manifest[A]))
+ protected def _pushAll[A : AsIterable](args: (String, A)*): DBObject =
+ apply("$pushAll")(args.map(z => z._1 -> AsIterable[A].asIterable(z._2)) :_*)
}
/*
@@ -203,7 +194,7 @@ trait PushAllOpBase extends BarewordQueryOperator {
* @see http://www.mongodb.org/display/DOCS/Updating#Updating-%24pushAll
*/
trait PushAllOp extends PushAllOpBase {
- def $pushAll[A <: Any: Manifest](args: (String, A)*): DBObject = _pushAll(args: _*)
+ def $pushAll[A : AsIterable](args: (String, A)*): DBObject = _pushAll(args: _*)
}
trait AddToSetOpBase extends BarewordQueryOperator {
@@ -304,17 +295,8 @@ trait PullOp extends PullOpBase {
}
trait PullAllOpBase extends BarewordQueryOperator {
- protected def _pullAll[A <: Any: Manifest](args: (String, A)*): DBObject =
- if (manifest[A] <:< manifest[Iterable[_]])
- apply("$pullAll")(args.map(z => z._1 -> z._2.asInstanceOf[Iterable[_]]): _*)
- else if (manifest[A] <:< manifest[Product])
- apply("$pullAll")(args.map(z => z._1 -> z._2.asInstanceOf[Product].productIterator.toIterable): _*)
- else if (manifest[A].erasure.isArray)
- apply("$pullAll")(args.map(z => z._1 -> z._2.asInstanceOf[Array[_]].toIterable): _*)
- else
- throw new IllegalArgumentException("$pullAll may only be invoked with a (String, A) where String is the field name and A is an Iterable or Product/Tuple of values (got %s).".format(manifest[A]))
-
-
+ protected def _pullAll[A : AsIterable](args: (String, A)*): DBObject =
+ apply("$pullAll")(args.map(z => z._1 -> AsIterable[A].asIterable(z._2)): _*)
}
/*
@@ -329,7 +311,7 @@ trait PullAllOpBase extends BarewordQueryOperator {
* @see http://www.mongodb.org/display/DOCS/Updating#Updating-%24pullAll
*/
trait PullAllOp extends PullAllOpBase {
- def $pullAll[A <: Any: Manifest](args: (String, A)*): DBObject = _pullAll(args: _*)
+ def $pullAll[A : AsIterable](args: (String, A)*): DBObject = _pullAll(args: _*)
}
trait AndOpBase {
View
304 casbah-query/src/main/scala/CoreOperators.scala
@@ -153,37 +153,8 @@ trait QueryOperator extends Logging {
*/
trait NotEqualsOp extends QueryOperator {
private val oper = "$ne"
-
- def $ne(target: String) = op(oper, target)
- def $ne(target: DBObject) = op(oper, target)
- def $ne(target: DBRef) = op(oper, target)
- def $ne(target: ObjectId) = op(oper, target)
- def $ne(target: Boolean) = op(oper, target)
- def $ne(target: Array[_]) = op(oper, target.toList)
- def $ne(target: Tuple1[_]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple2[_, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple3[_, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple4[_, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple5[_, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple6[_, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple7[_, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple8[_, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple9[_, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple10[_, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple11[_, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple12[_, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple13[_, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple14[_, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Iterable[_]) = op(oper, target.toList)
- def $ne[T: ValidDateOrNumericType](target: T) = op(oper, target)
+
+ def $ne[A : AsQueryParam](a:A) = op(oper, AsQueryParam[A].asQueryParam(a))
}
/**
@@ -198,34 +169,8 @@ trait NotEqualsOp extends QueryOperator {
*/
trait LessThanOp extends QueryOperator {
private val oper = "$lt"
-
- def $lt(target: String) = op(oper, target)
- def $lt(target: DBObject) = op(oper, target)
- def $lt(target: Array[_]) = op(oper, target.toList)
- def $lt(target: Tuple1[_]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple2[_, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple3[_, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple4[_, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple5[_, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple6[_, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple7[_, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple8[_, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple9[_, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple10[_, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple11[_, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple12[_, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple13[_, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple14[_, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Iterable[_]) = op(oper, target.toList)
- def $lt[T: ValidDateOrNumericType](target: T) = op(oper, target)
+
+ def $lt[A : AsQueryParam](a: A) = op(oper, AsQueryParam[A].asQueryParam(a))
}
/**
@@ -239,34 +184,8 @@ trait LessThanOp extends QueryOperator {
*/
trait LessThanEqualOp extends QueryOperator {
private val oper = "$lte"
-
- def $lte(target: String) = op(oper, target)
- def $lte(target: DBObject) = op(oper, target)
- def $lte(target: Array[_]) = op(oper, target.toList)
- def $lte(target: Tuple1[_]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple2[_, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple3[_, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple4[_, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple5[_, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple6[_, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple7[_, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple8[_, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple9[_, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple10[_, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple11[_, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple12[_, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple13[_, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple14[_, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Iterable[_]) = op(oper, target.toList)
- def $lte[T: ValidDateOrNumericType](target: T) = op(oper, target)
+
+ def $lte[A : AsQueryParam](a: A) = op(oper, AsQueryParam[A].asQueryParam(a))
}
/**
@@ -280,34 +199,8 @@ trait LessThanEqualOp extends QueryOperator {
*/
trait GreaterThanOp extends QueryOperator {
private val oper = "$gt"
-
- def $gt(target: String) = op(oper, target)
- def $gt(target: DBObject) = op(oper, target)
- def $gt(target: Array[_]) = op(oper, target.toList)
- def $gt(target: Tuple1[_]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple2[_, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple3[_, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple4[_, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple5[_, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple6[_, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple7[_, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple8[_, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple9[_, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple10[_, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple11[_, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple12[_, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple13[_, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple14[_, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Iterable[_]) = op(oper, target.toList)
- def $gt[T: ValidDateOrNumericType](target: T) = op(oper, target)
+
+ def $gt[A : AsQueryParam](a: A) = op(oper, AsQueryParam[A].asQueryParam(a))
}
/**
@@ -321,34 +214,8 @@ trait GreaterThanOp extends QueryOperator {
*/
trait GreaterThanEqualOp extends QueryOperator {
private val oper = "$gte"
-
- def $gte(target: String) = op(oper, target)
- def $gte(target: DBObject) = op(oper, target)
- def $gte(target: Array[_]) = op(oper, target.toList)
- def $gte(target: Tuple1[_]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple2[_, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple3[_, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple4[_, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple5[_, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple6[_, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple7[_, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple8[_, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple9[_, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple10[_, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple11[_, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple12[_, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple13[_, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple14[_, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Iterable[_]) = op(oper, target.toList)
- def $gte[T: ValidDateOrNumericType](target: T) = op(oper, target)
+
+ def $gte[A : AsQueryParam](a: A) = op(oper, AsQueryParam[A].asQueryParam(a))
}
/**
@@ -369,30 +236,7 @@ trait GreaterThanEqualOp extends QueryOperator {
trait InOp extends QueryOperator {
private val oper = "$in"
- def $in(target: Array[_]) = op(oper, target.toList)
- def $in(target: Tuple1[_]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple2[_, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple3[_, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple4[_, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple5[_, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple6[_, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple7[_, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple8[_, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple9[_, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple10[_, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple11[_, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple12[_, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple13[_, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple14[_, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Iterable[_]) = op(oper, target.toList)
+ def $in[A : AsQueryParam](a: A) = op(oper, AsQueryParam[A].asQueryParam(a))
}
/**
@@ -413,30 +257,7 @@ trait InOp extends QueryOperator {
trait NotInOp extends QueryOperator {
private val oper = "$nin"
- def $nin(target: Array[_]) = op(oper, target.toList)
- def $nin(target: Tuple1[_]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple2[_, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple3[_, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple4[_, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple5[_, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple6[_, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple7[_, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple8[_, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple9[_, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple10[_, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple11[_, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple12[_, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple13[_, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple14[_, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Iterable[_]) = op(oper, target.toList)
+ def $nin[A : AsQueryParam](a: A) = op(oper, AsQueryParam[A].asQueryParam(a))
}
/**
@@ -457,30 +278,7 @@ trait NotInOp extends QueryOperator {
trait AllOp extends QueryOperator {
private val oper = "$all"
- def $all(target: Array[_]) = op(oper, target.toList)
- def $all(target: Tuple1[_]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple2[_, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple3[_, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple4[_, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple5[_, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple6[_, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple7[_, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple8[_, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple9[_, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple10[_, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple11[_, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple12[_, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple13[_, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple14[_, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Iterable[_]) = op(oper, target.toList)
+ def $all[A : AsQueryParam](a: A) = op(oper, AsQueryParam[A].asQueryParam(a))
}
/**
@@ -609,28 +407,28 @@ trait ElemMatchOp extends QueryOperator {
def $elemMatch[A <% DBObject](target: A) = op(oper, target)
}
-abstract class BSONType[A]
+sealed abstract class BSONType[A](val operator: Byte)
object BSONType {
- implicit object BSONDouble extends BSONType[Double]
- implicit object BSONString extends BSONType[String]
- implicit object BSONObject extends BSONType[BSONObject]
- implicit object DBObject extends BSONType[DBObject]
- implicit object DBList extends BSONType[BasicDBList]
- implicit object BSONDBList extends BSONType[BasicBSONList]
- implicit object BSONBinary extends BSONType[Array[Byte]]
- implicit object BSONArray extends BSONType[Array[_]]
- implicit object BSONList extends BSONType[List[_]]
- implicit object BSONObjectId extends BSONType[ObjectId]
- implicit object BSONBoolean extends BSONType[Boolean]
- implicit object BSONJDKDate extends BSONType[java.util.Date]
- implicit object BSONJodaDateTime extends BSONType[org.joda.time.DateTime]
- implicit object BSONNull extends BSONType[Option[Nothing]]
- implicit object BSONRegex extends BSONType[Regex]
- implicit object BSONSymbol extends BSONType[Symbol]
- implicit object BSON32BitInt extends BSONType[Int]
- implicit object BSON64BitInt extends BSONType[Long]
- implicit object BSONSQLTimestamp extends BSONType[java.sql.Timestamp]
+ implicit object BSONDouble extends BSONType[Double](BSON.NUMBER)
+ implicit object BSONString extends BSONType[String](BSON.STRING)
+ implicit object BSONObject extends BSONType[BSONObject](BSON.OBJECT)
+ implicit object DBObject extends BSONType[DBObject](BSON.OBJECT)
+ implicit object DBList extends BSONType[BasicDBList](BSON.ARRAY)
+ implicit object BSONDBList extends BSONType[BasicBSONList](BSON.ARRAY)
+ implicit object BSONBinary extends BSONType[Array[Byte]](BSON.BINARY)
+ // implicit object BSONArray extends BSONType[Array[_]]
+ // implicit object BSONList extends BSONType[List[_]]
+ implicit object BSONObjectId extends BSONType[ObjectId](BSON.OID)
+ implicit object BSONBoolean extends BSONType[Boolean](BSON.BOOLEAN)
+ implicit object BSONJDKDate extends BSONType[java.util.Date](BSON.DATE)
+ implicit object BSONJodaDateTime extends BSONType[org.joda.time.DateTime](BSON.DATE)
+ implicit object BSONNull extends BSONType[Option[Nothing]](BSON.NULL)
+ implicit object BSONRegex extends BSONType[Regex](BSON.REGEX)
+ implicit object BSONSymbol extends BSONType[Symbol](BSON.SYMBOL)
+ implicit object BSON32BitInt extends BSONType[Int](BSON.NUMBER_INT)
+ implicit object BSON64BitInt extends BSONType[Long](BSON.NUMBER_LONG)
+ implicit object BSONSQLTimestamp extends BSONType[java.sql.Timestamp](BSON.TIMESTAMP)
}
/**
@@ -659,41 +457,7 @@ trait TypeOp extends QueryOperator {
* "foo".$type[Double]
*
*/
- def $type[A: BSONType: Manifest] =
- if (manifest[A] <:< manifest[Double])
- op(oper, BSON.NUMBER)
- else if (manifest[A] <:< manifest[String])
- op(oper, BSON.STRING)
- else if (manifest[A] <:< manifest[BasicDBList] ||
- manifest[A] <:< manifest[BasicBSONList])
- op(oper, BSON.ARRAY)
- else if (manifest[A] <:< manifest[BSONObject] ||
- manifest[A] <:< manifest[DBObject])
- op(oper, BSON.OBJECT)
- else if (manifest[A] <:< manifest[ObjectId])
- op(oper, BSON.OID)
- else if (manifest[A] <:< manifest[Boolean])
- op(oper, BSON.BOOLEAN)
- else if (manifest[A] <:< manifest[java.sql.Timestamp])
- op(oper, BSON.TIMESTAMP)
- else if (manifest[A] <:< manifest[java.util.Date] ||
- manifest[A] <:< manifest[org.joda.time.DateTime])
- op(oper, BSON.DATE)
- else if (manifest[A] <:< manifest[Option[Nothing]])
- op(oper, BSON.NULL)
- else if (manifest[A] <:< manifest[Regex])
- op(oper, BSON.REGEX)
- else if (manifest[A] <:< manifest[Symbol])
- op(oper, BSON.SYMBOL)
- else if (manifest[A] <:< manifest[Int])
- op(oper, BSON.NUMBER_INT)
- else if (manifest[A] <:< manifest[Long])
- op(oper, BSON.NUMBER_LONG)
- else if (manifest[A].erasure.isArray &&
- manifest[A] <:< manifest[Array[Byte]])
- op(oper, BSON.BINARY)
- else
- throw new IllegalArgumentException("Invalid BSON Type '%s' for matching".format(manifest.erasure))
+ def $type[A](implicit bsonType: BSONType[A]) = op(oper, bsonType.operator)
}
trait GeospatialOps extends GeoNearOp
View
60 casbah-query/src/main/scala/Implicits.scala
@@ -132,6 +132,66 @@ trait ValidBarewordExpressionArgTypeHolder {
implicit object CoreOperatorResultObjOk extends CoreOperatorResultObj
}
+trait AsIterable[A]{
+ def asIterable(a:A):Iterable[_]
+}
+
+object AsIterable {
+ def apply[A](implicit asIterable:AsIterable[A]) = asIterable
+
+ implicit def iterable[A <: Iterable[_]]:AsIterable[A] = new AsIterable[A]{
+ def asIterable(a: A) = a
+ }
+
+ implicit def product[A <: Product]:AsIterable[A] = new AsIterable[A]{
+ def asIterable(a: A) = a.productIterator.toIterable
+ }
+}
+
+@annotation.implicitNotFound("${A} is not a valid query parameter")
+trait AsQueryParam[A]{
+ def asQueryParam(a:A):Any
+}
+
+object AsQueryParam {
+ def apply[A](implicit a:AsQueryParam[A]) = a
+
+ private def as[A](f:A => Any):AsQueryParam[A] = new AsQueryParam[A]{
+ def asQueryParam(a: A) = f(a)
+ }
+
+ implicit val string = as[String](identity)
+ implicit def dbObject[A <: DBObject] = as[A](identity)
+ implicit val dbRef = as[DBRef](identity)
+ implicit val objectId = as[ObjectId](identity)
+ implicit val boolean = as[Boolean](identity)
+ implicit def array[A] = as[Array[A]](_.toList)
+ implicit def iterable[A <: Iterable[_]] = as[A](_.toList)
+ implicit def dateOrNumeric[A : ValidDateOrNumericType] = as[A](identity)
+ implicit def tuple1[A1] = as[Tuple1[A1]](_.productIterator.toList)
+ implicit def tuple2[A1,A2] = as[(A1,A2)](_.productIterator.toList)
+ implicit def tuple3[A1,A2,A3] = as[(A1,A2,A3)](_.productIterator.toList)
+ implicit def tuple4[A1,A2,A3,A4] = as[(A1,A2,A3,A4)](_.productIterator.toList)
+ implicit def tuple5[A1,A2,A3,A4,A5] = as[(A1,A2,A3,A4,A5)](_.productIterator.toList)
+ implicit def tuple6[A1,A2,A3,A4,A5,A6] = as[(A1,A2,A3,A4,A5,A6)](_.productIterator.toList)
+ implicit def tuple7[A1,A2,A3,A4,A5,A6,A7] = as[(A1,A2,A3,A4,A5,A6,A7)](_.productIterator.toList)
+ implicit def tuple8[A1,A2,A3,A4,A5,A6,A7,A8] = as[(A1,A2,A3,A4,A5,A6,A7,A8)](_.productIterator.toList)
+ implicit def tuple9[A1,A2,A3,A4,A5,A6,A7,A8,A9] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9)](_.productIterator.toList)
+ implicit def tuple10[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10)](_.productIterator.toList)
+ implicit def tuple11[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11)](_.productIterator.toList)
+ implicit def tuple12[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12)](_.productIterator.toList)
+ implicit def tuple13[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13)](_.productIterator.toList)
+ implicit def tuple14[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14)](_.productIterator.toList)
+ implicit def tuple15[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15)](_.productIterator.toList)
+ implicit def tuple16[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16)](_.productIterator.toList)
+ implicit def tuple17[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17)](_.productIterator.toList)
+ implicit def tuple18[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18)](_.productIterator.toList)
+ implicit def tuple19[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19)](_.productIterator.toList)
+ implicit def tuple20[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19,A20] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19,A20)](_.productIterator.toList)
+ implicit def tuple21[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19,A20,A21] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19,A20,A21)](_.productIterator.toList)
+ implicit def tuple22[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19,A20,A21,A22] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19,A20,A21,A22)](_.productIterator.toList)
+}
+
trait ValidNumericType[T]
trait ValidDateType[T]
View
14 casbah-query/src/test/scala/BarewordOperatorsSpec.scala
@@ -151,9 +151,10 @@ class BarewordOperatorsSpec extends CasbahMutableSpecification {
val push = $pushAll("foo" -> ("bar", "baz", "x", "y"))
push must haveListEntry("$pushAll.foo", List("bar", "baz", "x", "y"))
}
- "Not allow a non-list value" in {
- ($pushAll("foo" -> "bar")) must throwA[IllegalArgumentException]
- }
+// IS NOW A COMPILE ERROR
+// "Not allow a non-list value" in {
+// ($pushAll("foo" -> "bar")) must throwA[IllegalArgumentException]
+// }
"Accept multiple value lists" in {
val push = $pushAll("foo" -> ("bar", "baz", "x", "y"), "n" -> (5, 10, 12, 238))
push must haveListEntry("$pushAll.foo", List("bar", "baz", "x", "y"))
@@ -227,9 +228,10 @@ class BarewordOperatorsSpec extends CasbahMutableSpecification {
val pull = $pullAll("foo" -> ("bar", "baz", "x", "y"))
pull must haveEntry("$pullAll.foo" -> Seq("bar", "baz", "x", "y"))
}
- "Not allow a non-list value" in {
- ($pullAll("foo" -> "bar")) must throwA[IllegalArgumentException]
- }
+// IS NOW COMPILE ERROR
+// "Not allow a non-list value" in {
+// ($pullAll("foo" -> "bar")) must throwA[IllegalArgumentException]
+// }
"Accept multiple value lists" in {
val pull = $pullAll("foo" -> ("bar", "baz", "x", "y"), "n" -> (5, 10, 12, 238))
pull must haveEntry("$pullAll.foo" -> Seq("bar", "baz", "x", "y"))
View
7 project/CasbahBuild.scala
@@ -34,14 +34,14 @@ object CasbahBuild extends Build {
)
lazy val defaultSettings = baseSettings ++ Seq(
- libraryDependencies ++= Seq(scalatest(scalaVersion), slf4j, slf4jJCL),
+ libraryDependencies ++= Seq(scalatest(scalaVersion), slf4j, slf4jJCL, junit),
libraryDependencies <<= (scalaVersion, libraryDependencies) { (sv, deps) =>
val versionMap = Map("2.8.0" -> ("specs2_2.8.0", "1.5"),
"2.8.1" -> ("specs2_2.8.1", "1.5"),
"2.9.0" -> ("specs2_2.9.0", "1.7.1"),
"2.9.0-1" -> ("specs2_2.9.0", "1.7.1"),
"2.9.1" -> ("specs2_2.9.1", "1.7.1"))
- val tuple = versionMap.getOrElse(sv, error("Unsupported Scala version for Specs2"))
+ val tuple = versionMap.getOrElse(sv, sys.error("Unsupported Scala version for Specs2"))
deps :+ ("org.specs2" % tuple._1 % tuple._2)
},
autoCompilerPlugins := true,
@@ -75,7 +75,7 @@ object CasbahBuild extends Build {
lazy val core = Project(
id = "casbah-core",
base = file("casbah-core"),
- settings = defaultSettings
+ settings = defaultSettings ++ Seq(parallelExecution in Test := false)
) dependsOn(commons, query)
lazy val query = Project(
@@ -100,6 +100,7 @@ object Dependencies {
val specs2 = "org.specs2" %% "specs2" % "1.5.1" % "provided"
//val specs2 = specs2Compile % "test"
+ val junit = "junit" % "junit" % "4.10" % "test"
def specs2ScalazCore(scalaVer: sbt.SettingKey[String]) =
scalaVersionString(scalaVer) match {
View
2  project/build.properties
@@ -1 +1 @@
-sbt.version=0.11.1
+sbt.version=0.11.2
Please sign in to comment.
Something went wrong with that request. Please try again.