Standard logic in a subproject
parent
d6f27cafa4
commit
0dc35f3cbc
|
@ -1,59 +0,0 @@
|
|||
//import util.control.Exception.allCatch
|
||||
//import scalaz.{ Validation ⇒ SValidation, Success, Failure, Semigroup, Apply }
|
||||
|
||||
//trait Validation
|
||||
//extends scalaz.Validations
|
||||
//with scalaz.Semigroups
|
||||
//with scalaz.Options
|
||||
//with scalaz.Identitys {
|
||||
|
||||
//type Valid[A] = SValidation[Error, A]
|
||||
|
||||
//implicit def eitherToValidation[E, B](either: Either[E, B]): Valid[B] =
|
||||
//validation(either.left map {
|
||||
//case e: Error => e
|
||||
//case e: Throwable => Error(e)
|
||||
//case s: String => Error(s wrapNel)
|
||||
//})
|
||||
|
||||
//implicit def stringToError(str: String): Error = Error(str wrapNel)
|
||||
|
||||
//implicit def richStringToError(str: String) = new {
|
||||
//def toError: Error = stringToError(str)
|
||||
//}
|
||||
|
||||
//implicit def errorSemigroup: Semigroup[Error] = semigroup(_ |+| _)
|
||||
|
||||
//implicit def richValidation[A](validation: Valid[A]) = new {
|
||||
//def and[B](f: Valid[A => B])(implicit a: Apply[Valid]): Valid[B] = validation <*> f
|
||||
//}
|
||||
|
||||
//def unsafe[A](op: ⇒ A)(implicit handle: Throwable => Error = Error.apply): Valid[A] =
|
||||
//(allCatch either op).left map handle
|
||||
|
||||
//def validateOption[A, B](ao: Option[A])(op: A => Valid[B]): Valid[Option[B]] =
|
||||
//ao some { a ⇒ op(a) map (_.some) } none success(none)
|
||||
|
||||
//def sequenceValid[A](as: List[Valid[A]]): Valid[List[A]] =
|
||||
//as.sequence[({ type λ[α] = Valid[α] })#λ, A]
|
||||
//}
|
||||
|
||||
//import scalaz.NonEmptyList
|
||||
|
||||
//case class Error(messages: NonEmptyList[String]) {
|
||||
|
||||
//def |+|(error: Error): Error = Error(messages |+| error.messages)
|
||||
|
||||
//def messageList = messages.list
|
||||
|
||||
//def size = messageList.size
|
||||
|
||||
//override def toString = messageList map ("* " + _) mkString "\n"
|
||||
//}
|
||||
|
||||
//object Error {
|
||||
|
||||
//def apply(t: Throwable): Error = string(t.getMessage)
|
||||
|
||||
//def string(str: String): Error = Error(str wrapNel)
|
||||
//}
|
|
@ -27,7 +27,8 @@ application.langs="en"
|
|||
# db.default.user=sa
|
||||
# db.default.password=
|
||||
|
||||
mongo.host = localhost
|
||||
mongo.host = 127.0.0.1
|
||||
mongo.port = 27017
|
||||
mongo.dbname = lichess
|
||||
|
||||
# Evolutions
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package lila
|
||||
|
||||
import repo._
|
||||
import com.mongodb.casbah.MongoConnection
|
||||
import com.mongodb.casbah.commons.conversions.scala._
|
||||
|
||||
class Env(configuration: Map[String, Any]) {
|
||||
|
||||
def gameRepo = new GameRepo(mongodb("game2"))
|
||||
|
||||
private def mongoConnection = MongoConnection(
|
||||
get[String]("mongo.host"),
|
||||
get[Int]("mongo.port")
|
||||
)
|
||||
|
||||
private def mongodb = mongoConnection(
|
||||
get[String]("mongo.dbname")
|
||||
)
|
||||
|
||||
private def get[A](key: String) = configuration(key).asInstanceOf[A]
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package ornicar
|
||||
|
||||
import util.control.Exception.allCatch
|
||||
import scalaz.{ Validation ⇒ SValidation, Success, Failure, Semigroup, Apply, NonEmptyList }
|
||||
|
||||
trait Validation
|
||||
extends scalaz.Validations
|
||||
with scalaz.Semigroups
|
||||
with scalaz.Options
|
||||
with scalaz.MABs
|
||||
with scalaz.Identitys {
|
||||
|
||||
case class Error(messages: NonEmptyList[String]) {
|
||||
|
||||
def |+|(error: Error): Error = Error(messages |+| error.messages)
|
||||
|
||||
def size = messages.list.size
|
||||
|
||||
override def toString = messages.list map ("* " + _) mkString "\n"
|
||||
}
|
||||
|
||||
object Error {
|
||||
|
||||
def apply(t: Throwable): Error = string(t.getMessage)
|
||||
|
||||
def string(str: String): Error = Error(str wrapNel)
|
||||
}
|
||||
|
||||
type Valid[A] = SValidation[Error, A]
|
||||
|
||||
implicit def eitherToValidation[E, B](either: Either[E, B]): Valid[B] =
|
||||
validation(either.left map {
|
||||
case e: Error => e
|
||||
case e: Throwable => Error(e)
|
||||
case s: String => Error(s wrapNel)
|
||||
})
|
||||
|
||||
implicit def stringToError(str: String): Error = Error(str wrapNel)
|
||||
|
||||
implicit def richStringToError(str: String) = new {
|
||||
def toError: Error = stringToError(str)
|
||||
}
|
||||
|
||||
implicit def errorSemigroup: Semigroup[Error] = semigroup(_ |+| _)
|
||||
|
||||
implicit def richValidation[A](validation: Valid[A]) = new {
|
||||
def and[B](f: Valid[A => B])(implicit a: Apply[Valid]): Valid[B] = validation <*> f
|
||||
}
|
||||
|
||||
def unsafe[A](op: ⇒ A)(implicit handle: Throwable => Error = Error.apply): Valid[A] =
|
||||
(allCatch either op).left map handle
|
||||
|
||||
def validateOption[A, B](ao: Option[A])(op: A => Valid[B]): Valid[Option[B]] =
|
||||
ao some { a ⇒ op(a) map (_.some) } none success(none)
|
||||
|
||||
def sequenceValid[A](as: List[Valid[A]]): Valid[List[A]] =
|
||||
as.sequence[({ type λ[α] = Valid[α] })#λ, A]
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package lila
|
||||
package model
|
||||
|
||||
import com.novus.salat.annotations._
|
||||
import com.mongodb.casbah.Imports._
|
||||
|
||||
case class Game(
|
||||
|
||||
@Key("_id") id: String
|
||||
)
|
|
@ -1,7 +1,7 @@
|
|||
package object lila
|
||||
//extends Validation
|
||||
extends ornicar.Validation
|
||||
//with DateTime
|
||||
extends scalaz.Identitys
|
||||
with scalaz.Identitys
|
||||
with scalaz.Equals
|
||||
with scalaz.MABs
|
||||
with scalaz.Options
|
|
@ -0,0 +1,12 @@
|
|||
package lila
|
||||
package repo
|
||||
|
||||
import model._
|
||||
import com.novus.salat._
|
||||
import com.novus.salat.global._
|
||||
import com.novus.salat.dao._
|
||||
import com.mongodb.casbah.MongoCollection
|
||||
import com.mongodb.casbah.Imports._
|
||||
|
||||
class GameRepo(collection: MongoCollection) extends SalatDAO[Game, String](collection) {
|
||||
}
|
|
@ -25,15 +25,28 @@ trait Dependencies {
|
|||
|
||||
object ApplicationBuild extends Build with Resolvers with Dependencies {
|
||||
|
||||
val appName = "lila"
|
||||
val appVersion = "1.0-SNAPSHOT"
|
||||
|
||||
val main = PlayProject(appName, appVersion, Seq(
|
||||
scalaz, specs2, redis, json, slf4jNop
|
||||
), mainLang = SCALA).settings(
|
||||
val lila = Project("lila", file("lila")).settings(
|
||||
libraryDependencies := Seq(
|
||||
scalaz, specs2, redis, json, slf4jNop, casbah, salat
|
||||
),
|
||||
resolvers := Seq(
|
||||
codahale, typesafe, iliaz, sonatype
|
||||
)
|
||||
),
|
||||
shellPrompt := ShellPrompt.buildShellPrompt
|
||||
)
|
||||
|
||||
val main = PlayProject("app", appVersion, Seq(), mainLang = SCALA) dependsOn lila
|
||||
}
|
||||
|
||||
object ShellPrompt {
|
||||
|
||||
val buildShellPrompt = {
|
||||
(state: State) ⇒
|
||||
{
|
||||
val currProject = Project.extract(state).currentProject.id
|
||||
"%s> ".format(currProject)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue