diff --git a/build.sbt b/build.sbt index 80231ee3..01d1cf8b 100644 --- a/build.sbt +++ b/build.sbt @@ -50,11 +50,20 @@ lazy val `sphere-json` = project.in(file("./json")) .settings(homepage := Some(url("https://github.com/sphereio/sphere-scala-libs/blob/master/json/README.md"))) .dependsOn(`sphere-util`) -lazy val `sphere-mongo` = project.in(file("./mongo")) +lazy val `sphere-mongo-core` = project.in(file("./mongo/mongo-core")) .settings(standardSettings: _*) - .settings(Fmpp.settings: _*) .dependsOn(`sphere-util`) +lazy val `sphere-mongo-derivation` = project.in(file("./mongo/mongo-derivation")) + .settings(standardSettings: _*) + .settings(Fmpp.settings: _*) + .dependsOn(`sphere-mongo-core`) + +lazy val `sphere-mongo` = project.in(file("./mongo")) + .settings(standardSettings: _*) + .settings(homepage := Some(url("https://github.com/sphereio/sphere-scala-libs/blob/master/mongo/README.md"))) + .aggregate(`sphere-mongo-core`, `sphere-mongo-derivation`) + // benchmarks lazy val benchmarks = project diff --git a/mongo/dependencies.sbt b/mongo/mongo-core/dependencies.sbt similarity index 100% rename from mongo/dependencies.sbt rename to mongo/mongo-core/dependencies.sbt diff --git a/mongo/src/main/scala/io/sphere/mongo/catsinstances/package.scala b/mongo/mongo-core/src/main/scala/io/sphere/mongo/catsinstances/package.scala similarity index 100% rename from mongo/src/main/scala/io/sphere/mongo/catsinstances/package.scala rename to mongo/mongo-core/src/main/scala/io/sphere/mongo/catsinstances/package.scala diff --git a/mongo/src/main/scala/io/sphere/mongo/format/DefaultMongoFormats.scala b/mongo/mongo-core/src/main/scala/io/sphere/mongo/format/DefaultMongoFormats.scala similarity index 100% rename from mongo/src/main/scala/io/sphere/mongo/format/DefaultMongoFormats.scala rename to mongo/mongo-core/src/main/scala/io/sphere/mongo/format/DefaultMongoFormats.scala diff --git a/mongo/src/main/scala/io/sphere/mongo/format/MongoFormat.scala b/mongo/mongo-core/src/main/scala/io/sphere/mongo/format/MongoFormat.scala similarity index 100% rename from mongo/src/main/scala/io/sphere/mongo/format/MongoFormat.scala rename to mongo/mongo-core/src/main/scala/io/sphere/mongo/format/MongoFormat.scala diff --git a/mongo/src/main/scala/io/sphere/mongo/format/package.scala b/mongo/mongo-core/src/main/scala/io/sphere/mongo/format/package.scala similarity index 100% rename from mongo/src/main/scala/io/sphere/mongo/format/package.scala rename to mongo/mongo-core/src/main/scala/io/sphere/mongo/format/package.scala diff --git a/mongo/src/test/scala/io/sphere/mongo/MongoUtils.scala b/mongo/mongo-core/src/test/scala/io/sphere/mongo/MongoUtils.scala similarity index 100% rename from mongo/src/test/scala/io/sphere/mongo/MongoUtils.scala rename to mongo/mongo-core/src/test/scala/io/sphere/mongo/MongoUtils.scala diff --git a/mongo/src/test/scala/io/sphere/mongo/catsinstances/MongoFormatCatsInstancesTest.scala b/mongo/mongo-core/src/test/scala/io/sphere/mongo/catsinstances/MongoFormatCatsInstancesTest.scala similarity index 100% rename from mongo/src/test/scala/io/sphere/mongo/catsinstances/MongoFormatCatsInstancesTest.scala rename to mongo/mongo-core/src/test/scala/io/sphere/mongo/catsinstances/MongoFormatCatsInstancesTest.scala diff --git a/mongo/src/test/scala/io/sphere/mongo/format/BaseMoneyMongoFormatTest.scala b/mongo/mongo-core/src/test/scala/io/sphere/mongo/format/BaseMoneyMongoFormatTest.scala similarity index 100% rename from mongo/src/test/scala/io/sphere/mongo/format/BaseMoneyMongoFormatTest.scala rename to mongo/mongo-core/src/test/scala/io/sphere/mongo/format/BaseMoneyMongoFormatTest.scala diff --git a/mongo/src/test/scala/io/sphere/mongo/format/DefaultMongoFormatsTest.scala b/mongo/mongo-core/src/test/scala/io/sphere/mongo/format/DefaultMongoFormatsTest.scala similarity index 89% rename from mongo/src/test/scala/io/sphere/mongo/format/DefaultMongoFormatsTest.scala rename to mongo/mongo-core/src/test/scala/io/sphere/mongo/format/DefaultMongoFormatsTest.scala index 67644b62..6f02b2fb 100644 --- a/mongo/src/test/scala/io/sphere/mongo/format/DefaultMongoFormatsTest.scala +++ b/mongo/mongo-core/src/test/scala/io/sphere/mongo/format/DefaultMongoFormatsTest.scala @@ -1,8 +1,10 @@ package io.sphere.mongo.format import java.util.Locale + +import com.mongodb.DBObject +import io.sphere.mongo.MongoUtils import io.sphere.mongo.format.DefaultMongoFormats._ -import io.sphere.mongo.generic._ import io.sphere.util.LangTag import org.bson.BasicBSONObject import org.bson.types.BasicBSONList @@ -16,7 +18,14 @@ import scala.collection.JavaConverters._ object DefaultMongoFormatsTest { case class User(name: String) object User { - implicit val mongo: MongoFormat[User] = mongoProduct(apply _) + implicit val mongo: MongoFormat[User] = new MongoFormat[User] { + override def toMongoValue(a: User): Any = MongoUtils.dbObj("name" -> a.name) + override def fromMongoValue(any: Any): User = any match { + case dbo: DBObject => + User(dbo.get("name").asInstanceOf[String]) + case _ => throw new Exception("expected DBObject") + } + } } } diff --git a/mongo/src/main/java/io/sphere/mongo/generic/annotations/MongoEmbedded.java b/mongo/mongo-derivation/src/main/java/io/sphere/mongo/generic/annotations/MongoEmbedded.java similarity index 100% rename from mongo/src/main/java/io/sphere/mongo/generic/annotations/MongoEmbedded.java rename to mongo/mongo-derivation/src/main/java/io/sphere/mongo/generic/annotations/MongoEmbedded.java diff --git a/mongo/src/main/java/io/sphere/mongo/generic/annotations/MongoIgnore.java b/mongo/mongo-derivation/src/main/java/io/sphere/mongo/generic/annotations/MongoIgnore.java similarity index 100% rename from mongo/src/main/java/io/sphere/mongo/generic/annotations/MongoIgnore.java rename to mongo/mongo-derivation/src/main/java/io/sphere/mongo/generic/annotations/MongoIgnore.java diff --git a/mongo/src/main/java/io/sphere/mongo/generic/annotations/MongoKey.java b/mongo/mongo-derivation/src/main/java/io/sphere/mongo/generic/annotations/MongoKey.java similarity index 100% rename from mongo/src/main/java/io/sphere/mongo/generic/annotations/MongoKey.java rename to mongo/mongo-derivation/src/main/java/io/sphere/mongo/generic/annotations/MongoKey.java diff --git a/mongo/src/main/java/io/sphere/mongo/generic/annotations/MongoTypeHint.java b/mongo/mongo-derivation/src/main/java/io/sphere/mongo/generic/annotations/MongoTypeHint.java similarity index 100% rename from mongo/src/main/java/io/sphere/mongo/generic/annotations/MongoTypeHint.java rename to mongo/mongo-derivation/src/main/java/io/sphere/mongo/generic/annotations/MongoTypeHint.java diff --git a/mongo/src/main/java/io/sphere/mongo/generic/annotations/MongoTypeHintField.java b/mongo/mongo-derivation/src/main/java/io/sphere/mongo/generic/annotations/MongoTypeHintField.java similarity index 100% rename from mongo/src/main/java/io/sphere/mongo/generic/annotations/MongoTypeHintField.java rename to mongo/mongo-derivation/src/main/java/io/sphere/mongo/generic/annotations/MongoTypeHintField.java diff --git a/mongo/src/main/scala/io/sphere/mongo/generic/MongoFormatMacros.scala b/mongo/mongo-derivation/src/main/scala/io/sphere/mongo/generic/MongoFormatMacros.scala similarity index 100% rename from mongo/src/main/scala/io/sphere/mongo/generic/MongoFormatMacros.scala rename to mongo/mongo-derivation/src/main/scala/io/sphere/mongo/generic/MongoFormatMacros.scala diff --git a/mongo/src/main/scala/io/sphere/mongo/generic/package.fmpp.scala b/mongo/mongo-derivation/src/main/scala/io/sphere/mongo/generic/package.fmpp.scala similarity index 100% rename from mongo/src/main/scala/io/sphere/mongo/generic/package.fmpp.scala rename to mongo/mongo-derivation/src/main/scala/io/sphere/mongo/generic/package.fmpp.scala diff --git a/mongo/mongo-derivation/src/test/scala/io/sphere/mongo/MongoUtils.scala b/mongo/mongo-derivation/src/test/scala/io/sphere/mongo/MongoUtils.scala new file mode 100644 index 00000000..14bcc57a --- /dev/null +++ b/mongo/mongo-derivation/src/test/scala/io/sphere/mongo/MongoUtils.scala @@ -0,0 +1,9 @@ +package io.sphere.mongo +import com.mongodb.BasicDBObject + +object MongoUtils { + + def dbObj(pairs: (String, Any)*) = + pairs.foldLeft(new BasicDBObject){case (obj, (key, value)) => obj.append(key, value)} + +} diff --git a/mongo/src/test/scala/io/sphere/mongo/SerializationTest.scala b/mongo/mongo-derivation/src/test/scala/io/sphere/mongo/SerializationTest.scala similarity index 100% rename from mongo/src/test/scala/io/sphere/mongo/SerializationTest.scala rename to mongo/mongo-derivation/src/test/scala/io/sphere/mongo/SerializationTest.scala diff --git a/mongo/src/test/scala/io/sphere/mongo/format/OptionMongoFormatSpec.scala b/mongo/mongo-derivation/src/test/scala/io/sphere/mongo/format/OptionMongoFormatSpec.scala similarity index 100% rename from mongo/src/test/scala/io/sphere/mongo/format/OptionMongoFormatSpec.scala rename to mongo/mongo-derivation/src/test/scala/io/sphere/mongo/format/OptionMongoFormatSpec.scala diff --git a/mongo/src/test/scala/io/sphere/mongo/generic/DefaultValuesSpec.scala b/mongo/mongo-derivation/src/test/scala/io/sphere/mongo/generic/DefaultValuesSpec.scala similarity index 100% rename from mongo/src/test/scala/io/sphere/mongo/generic/DefaultValuesSpec.scala rename to mongo/mongo-derivation/src/test/scala/io/sphere/mongo/generic/DefaultValuesSpec.scala diff --git a/mongo/src/test/scala/io/sphere/mongo/generic/DeriveMongoformatSpec.scala b/mongo/mongo-derivation/src/test/scala/io/sphere/mongo/generic/DeriveMongoformatSpec.scala similarity index 100% rename from mongo/src/test/scala/io/sphere/mongo/generic/DeriveMongoformatSpec.scala rename to mongo/mongo-derivation/src/test/scala/io/sphere/mongo/generic/DeriveMongoformatSpec.scala diff --git a/mongo/src/test/scala/io/sphere/mongo/generic/MongoEmbeddedSpec.scala b/mongo/mongo-derivation/src/test/scala/io/sphere/mongo/generic/MongoEmbeddedSpec.scala similarity index 100% rename from mongo/src/test/scala/io/sphere/mongo/generic/MongoEmbeddedSpec.scala rename to mongo/mongo-derivation/src/test/scala/io/sphere/mongo/generic/MongoEmbeddedSpec.scala diff --git a/mongo/src/test/scala/io/sphere/mongo/generic/MongoKeySpec.scala b/mongo/mongo-derivation/src/test/scala/io/sphere/mongo/generic/MongoKeySpec.scala similarity index 100% rename from mongo/src/test/scala/io/sphere/mongo/generic/MongoKeySpec.scala rename to mongo/mongo-derivation/src/test/scala/io/sphere/mongo/generic/MongoKeySpec.scala diff --git a/mongo/src/test/scala/io/sphere/mongo/generic/MongoTypeHintFieldSpec.scala b/mongo/mongo-derivation/src/test/scala/io/sphere/mongo/generic/MongoTypeHintFieldSpec.scala similarity index 100% rename from mongo/src/test/scala/io/sphere/mongo/generic/MongoTypeHintFieldSpec.scala rename to mongo/mongo-derivation/src/test/scala/io/sphere/mongo/generic/MongoTypeHintFieldSpec.scala