/src/main/scala/couch/db/Document.scala

http://scouchdb.googlecode.com/ · Scala · 43 lines · 34 code · 9 blank · 0 comment · 8 complexity · d48392dff7ba1bb2d1824ad3113b7111 MD5 · raw file

  1. package couch.db
  2. import couch.json._
  3. import scala.reflect._
  4. object DesignDocument {
  5. val PREFIX = "_design/"
  6. def extendId(id: String) =
  7. if (id == null || id.length == 0)
  8. throw new IllegalArgumentException("invalid id entered:" + id)
  9. else PREFIX + id
  10. }
  11. @BeanInfo
  12. case class DesignDocument(var _id: String,
  13. @JSONProperty("") {val ignoreIfNull = true, val ignore = false }
  14. _rev: String,
  15. @OptionTypeHint(classOf[Map[_,_]])
  16. @JSONTypeHint(classOf[View])
  17. views: Map[String, View]) {
  18. if (_id != null)
  19. if (!_id.startsWith(DesignDocument.PREFIX))
  20. _id = DesignDocument.extendId(_id)
  21. var language = "javascript"
  22. private [db] def this() = this(null, null, Map[String, View]())
  23. override def toString = {
  24. "_id = " + _id + " _rev = " + _rev + " language = " + language + " " +
  25. (views match {
  26. case null => ""
  27. case v => {
  28. v.map(e =>
  29. (e._1.toString + ":" + e._2.toString)).mkString(",")
  30. }
  31. }
  32. )
  33. }
  34. }