diff --git a/project/build.properties b/project/build.properties index 8b542a3..cdb31ae 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1,6 +1,6 @@ #Project properties #Wed Feb 03 09:29:37 EST 2010 -project.organization=prohax +project.organization=nkpart project.name=sage sbt.version=0.6.10 project.version=0.1 diff --git a/project/build/sage.scala b/project/build/sage.scala index 4f1b1f0..6637201 100644 --- a/project/build/sage.scala +++ b/project/build/sage.scala @@ -1,12 +1,12 @@ import sbt._ class SageProject(info: ProjectInfo) extends DefaultProject(info) { - - Credentials.add("Secure Area", "localhost", "admin", "admin123") - - override def managedStyle = ManagedStyle.Maven - val publishTo = "Secure Area" at "http://localhost:8080/" - + // + // Credentials.add("Secure Area", "localhost", "admin", "admin123") + // + // override def managedStyle = ManagedStyle.Maven + // val publishTo = "Secure Area" at "http://localhost:8080/" + // val snapshots = "scala-tools snapshots" at "http://www.scala-tools.org/repo-snapshots" val scalatest = "org.scalatest" % "scalatest" % "1.0.1-for-scala-2.8.0.Beta1-RC7-with-test-interfaces-0.3-SNAPSHOT" % "test" @@ -18,4 +18,6 @@ class SageProject(info: ProjectInfo) extends DefaultProject(info) { val scalaz_core = "com.googlecode.scalaz" % "scalaz-core_2.8.0.Beta1" % "5.0-SNAPSHOT" val scalaz_http = "com.googlecode.scalaz" % "scalaz-http_2.8.0.Beta1" % "5.0-SNAPSHOT" + + val hprops = "nkpart" %% "hprops" % "0.1" } diff --git a/src/main/scala/props/FunctionWs.scala b/src/main/scala/props/FunctionWs.scala deleted file mode 100644 index b834832..0000000 --- a/src/main/scala/props/FunctionWs.scala +++ /dev/null @@ -1,61 +0,0 @@ -package props - -import Function._ - -import metascala.HLists._ -import metascala.Nats._ - -trait FunctionWs { - implicit def pimp1[A, Z](f: A => Z) = new { - def m: A :: HNil => Z = list => f(list.nth[_0]) - def <->(unapply: Z => Option[A]) = (m, (z: Z) => unapply(z).get :: HNil ) - } - - implicit def pimp2[A, B, Z](f: (A, B) => Z) = new { - def m: A :: B :: HNil => Z = list => f(list.nth[_0], list.nth[_1]) - - def <->(unapply: Z => Option[(A,B)]) = (m, (z: Z) => unapply(z).get match { case (a,b) => a :: b :: HNil }) - } - - implicit def pimp3[A, B, C, Z](f: (A, B, C) => Z) = new { - def m: A :: B :: C :: HNil => Z = list => f(list.nth[_0], list.nth[_1], list.nth[_2]) - - def <->(unapply: Z => Option[(A,B,C)]) = - (m, (z: Z) => unapply(z).get match { case (a,b,c) => a :: b :: c :: HNil }) - } - - implicit def pimp4[A, B, C, D, Z](f: (A, B, C, D) => Z) = new { - def m: A :: B :: C :: D :: HNil => Z = list => f(list.nth[_0], list.nth[_1], list.nth[_2], list.nth[_3]) - - def <->(unapply: Z => Option[(A,B,C,D)]) = - (m, (z: Z) => unapply(z).get match { case (a,b,c,d) => a :: b :: c :: d :: HNil }) - } - - implicit def pimp5[A, B, C, D, E, Z](f: (A, B, C, D, E) => Z) = new { - def m: A :: B :: C :: D :: E :: HNil => Z = list => f(list.nth[_0], list.nth[_1], list.nth[_2], list.nth[_3], list.nth[_4]) - - def <->(unapply: Z => Option[(A,B,C,D,E)]) = - (m, (z: Z) => unapply(z).get match { case (a,b,c,d,e) => a :: b :: c :: d :: e :: HNil }) - } - - implicit def pimp6[A, B, C, D, E, F, Z](f: (A, B, C, D, E, F) => Z) = new { - def m: A :: B :: C :: D :: E :: F :: HNil => Z = list => f(list.nth[_0], list.nth[_1], list.nth[_2], list.nth[_3], list.nth[_4], list.nth[_5]) - - def <->(unapply: Z => Option[(A,B,C,D,E,F)]) = - (m, (z: Z) => unapply(z).get match { case (a,b,c,d,e,f) => a :: b :: c :: d :: e :: f :: HNil }) - } - - implicit def pimp7[A, B, C, D, E, F, G, Z](f: (A, B, C, D, E, F, G) => Z) = new { - def m: A :: B :: C :: D :: E :: F :: G :: HNil => Z = list => f(list.nth[_0], list.nth[_1], list.nth[_2], list.nth[_3], list.nth[_4], list.nth[_5], list.nth[_6]) - - def <->(unapply: Z => Option[(A,B,C,D,E,F,G)]) = - (m, (z: Z) => unapply(z).get match { case (a,b,c,d,e,f,g) => a :: b :: c :: d :: e :: f :: g :: HNil }) - } - - implicit def pimp8[A, B, C, D, E, F, G, H, Z](f: (A, B, C, D, E, F, G, H) => Z) = new { - def m: A :: B :: C :: D :: E :: F :: G :: H :: HNil => Z = list => f(list.nth[_0], list.nth[_1], list.nth[_2], list.nth[_3], list.nth[_4], list.nth[_5], list.nth[_6], list.nth[_7]) - - def <->(unapply: Z => Option[(A,B,C,D,E,F,G,H)]) = - (m, (z: Z) => unapply(z).get match { case (a,b,c,d,e,f,g,h) => a :: b :: c :: d :: e :: f :: g :: h :: HNil }) - } -} \ No newline at end of file diff --git a/src/main/scala/props/Instances.scala b/src/main/scala/props/Instances.scala deleted file mode 100644 index 3d76866..0000000 --- a/src/main/scala/props/Instances.scala +++ /dev/null @@ -1,37 +0,0 @@ -package props - -trait Instances { - import scalaz._ - import Scalaz._ - - // Properties are invariant functors - implicit def ReadWriteInvariantFunctor[Src]: InvariantFunctor[PartialApply1Of2[ReadWrite, Src]#Apply] = - new scalaz.InvariantFunctor[PartialApply1Of2[ReadWrite, Src]#Apply] { - def xmap[T, U](prop: ReadWrite[Src, T], f: T => U, g: U => T): ReadWrite[Src, U] = ReadWrite[Src, U]( - e => prop.get(e) map f, - (u, e) => prop.put(g(u), e) - ) - } - - // Properties are invariant functors - implicit def ReadUpdateInvariantFunctor[Src]: InvariantFunctor[PartialApply1Of2[ReadUpdate, Src]#Apply] = - new scalaz.InvariantFunctor[PartialApply1Of2[ReadUpdate, Src]#Apply] { - def xmap[T, U](prop: ReadUpdate[Src, T], f: T => U, g: U => T): ReadUpdate[Src, U] = new ReadUpdate[Src, U] { - def get(s: Src) = prop.get(s) map f - - def put(s: Src, u: U): Result[U] = prop.put(s, g(u)) map f - } - } - - implicit def AttrReaderFunctor[Src] = new scalaz.Functor[PartialApply1Of2[AttrReader, Src]#Apply] { - def fmap[A,B](reader: AttrReader[Src, A], f: A => B) = new AttrReader[Src, B] { - def get(s: Src): Validation[NonEmptyList[PropertyError], B] = reader.get(s) map f - } - } - - implicit def AttrWriterCofunctor[Src] = new scalaz.Cofunctor[PartialApply1Of2[AttrWriter, Src]#Apply] { - def comap[A,B](writer: AttrWriter[Src, A], f: B => A) = new AttrWriter[Src, B] { - def put(b: B, s: Src) = writer.put(f(b), s) - } - } -} \ No newline at end of file diff --git a/src/main/scala/props/MA.scala b/src/main/scala/props/MA.scala deleted file mode 100644 index 90fb8a9..0000000 --- a/src/main/scala/props/MA.scala +++ /dev/null @@ -1,9 +0,0 @@ -package props - -import scalaz._ -import Scalaz._ - -trait MAs { - implicit def readWriteMA[Src, T](p: ReadWrite[Src,T]) = ma[PartialApply1Of2[ReadWrite, Src]#Apply, T](p) - implicit def readUpdateMA[Src, T](p: ReadUpdate[Src,T]) = ma[PartialApply1Of2[ReadUpdate, Src]#Apply, T](p) -} diff --git a/src/main/scala/props/Property.scala b/src/main/scala/props/Property.scala deleted file mode 100644 index cf5c275..0000000 --- a/src/main/scala/props/Property.scala +++ /dev/null @@ -1,50 +0,0 @@ -package props - -import scalaz._ -import Scalaz._ - -import metascala.HLists._ -import metascala.Nats._ - -sealed trait PropertyError { - val property: String -} - -case class Missing(property: String) extends PropertyError -case class Invalid(property: String) extends PropertyError - -trait AttrReader[Src, T] { - // Failure cases must report a missing property/field name - def get(e: Src): Result[T] -} - -trait AttrWriter[Src, T] { - def put(t: T, e: Src): Result[Src] -} - -// Represents getting a value that can be read from, and written to, a source type. -// This is a type that can be encoded in (and decoded from) Src -// eg. ReadWrite[JSONObject, Person] -trait ReadWrite[Src, T] extends AttrReader[Src,T] with AttrWriter[Src, T] { - // Helper for working with case classes, should be able to call like this (note the <-> helper from FunctionWs): - // case class Foo(...) - // someProp >< (Foo <-> Foo.unapply _) - def ><[U](t2: (T => U, U => T)): ReadWrite[Src, U] = this.xmap(t2._1, t2._2) -} - -object ReadWrite { - def apply[Src, T](getF: Src => Result[T], putF: (T, Src) => Result[Src]) = new ReadWrite[Src, T] { - def get(e: Src) = getF(e) - def put(t: T, e: Src) = putF(t, e) - } -} - -// Represents a value that can be read from, and updated from, a source type. -// eg. ReadUpdate[HttpRequest, Person] -// an existing person value can be updated -// with values from the request, or a new person -// could be created. -trait ReadUpdate[Src, T] extends AttrReader[Src, T] with AttrWriter[T, Src] { - def ><[U](t2: (T => U, U => T)): ReadUpdate[Src, U] = this.xmap(t2._1, t2._2) -} - diff --git a/src/main/scala/props/PropsDSL.scala b/src/main/scala/props/PropsDSL.scala deleted file mode 100644 index dc06a03..0000000 --- a/src/main/scala/props/PropsDSL.scala +++ /dev/null @@ -1,45 +0,0 @@ -package props - -import metascala.HLists._ - -import scalaz._ -import Scalaz._ - -// Provides the DSL for composing properties -trait PropsDSL { - def hlift[T, P[_]: InvariantFunctor](p: P[T]): P[HCons[T, HNil]] = p.xmap(v => HCons(v, HNil), (xs: HCons[T, HNil]) => xs.head) - - implicit def pimpPropListThing[Src, L <: HList](p: ReadWrite[Src, L]) = new { - def ::[V](property: ReadWrite[Src, V]): ReadWrite[Src, HCons[V, L]] = ReadWrite[Src, HCons[V, L]]( - e => (property.get(e) <|*|> p.get(e)) map { case (v, xs) => HCons(v, xs) }, - (vls, e) => { - p.put(vls.tail, e) >>= (x => property.put(vls.head, x)) - } - ) - } - - implicit def pimpPropThing[Src, L](p: ReadWrite[Src, L]) = new { - def ::[V](property: ReadWrite[Src, V]): ReadWrite[Src, HCons[V, HCons[L, HNil]]] = - property :: PropsDSL.this.hlift[L, PartialApply1Of2[ReadWrite, Src]#Apply](p) - - def hlift = PropsDSL.this.hlift[L, PartialApply1Of2[ReadWrite, Src]#Apply](p) - } - - implicit def pimpReadUpdateList[Src, L <: HList](p: ReadUpdate[Src, L]) = new { - def ::[V](property: ReadUpdate[Src, V]): ReadUpdate[Src, HCons[V, L]] = new ReadUpdate[Src, HCons[V, L]] { - def get(s: Src) = (property.get(s) <|*|> p.get(s)) map { case (v, xs) => HCons(v, xs) } - def put(s: Src, vls: HCons[V, L]) = { - val ell = p.put(s, vls.tail) - val v = property.put(s, vls.head) - (v <|*|> ell) map { case (v, ell) => HCons(v, ell) } - } - } - } - - implicit def pimpReadUpdateProp[Src, L](p: ReadUpdate[Src, L]) = new { - def ::[V](property: ReadUpdate[Src, V]): ReadUpdate[Src, HCons[V, HCons[L, HNil]]] = - property :: PropsDSL.this.hlift[L, PartialApply1Of2[ReadUpdate, Src]#Apply](p) - - def hlift = PropsDSL.this.hlift[L, PartialApply1Of2[ReadUpdate, Src]#Apply](p) - } -} diff --git a/src/main/scala/props/package.scala b/src/main/scala/props/package.scala deleted file mode 100644 index 181da8e..0000000 --- a/src/main/scala/props/package.scala +++ /dev/null @@ -1,11 +0,0 @@ -import metascala.HLists._ - -package object props extends PropsDSL with MAs with Instances { - import scalaz._ - import Scalaz._ - - def missing(s: String): PropertyError = Missing(s) - def invalid(s: String): PropertyError = Invalid(s) - - type Result[T] = Validation[NonEmptyList[PropertyError], T] -} diff --git a/src/main/scala/sage/EntityBase.scala b/src/main/scala/sage/EntityBase.scala index f89f61e..2d20667 100644 --- a/src/main/scala/sage/EntityBase.scala +++ b/src/main/scala/sage/EntityBase.scala @@ -1,6 +1,6 @@ package sage -import props._ +import hprops._ import scalaz._ import Scalaz._ import com.google.appengine.api.datastore._ diff --git a/src/main/scala/sage/EntityProperties.scala b/src/main/scala/sage/EntityProperties.scala index d92e876..515f9b5 100644 --- a/src/main/scala/sage/EntityProperties.scala +++ b/src/main/scala/sage/EntityProperties.scala @@ -1,6 +1,6 @@ package sage -import props._ +import hprops._ import scalaz._ import Scalaz._ import com.google.appengine.api.datastore._ diff --git a/src/main/scala/sage/http/Postable.scala b/src/main/scala/sage/http/Postable.scala index 06b0757..5a20c24 100644 --- a/src/main/scala/sage/http/Postable.scala +++ b/src/main/scala/sage/http/Postable.scala @@ -1,7 +1,7 @@ package sage package http -import props._ +import hprops._ import scalaz.http.request._ import scalaz._ import Scalaz._ @@ -11,7 +11,7 @@ import metascala.HLists._ trait StringW { val str: String - import props._ + import hprops._ def as[T](implicit p: Postable[T]) = new ReadUpdate[Request[Stream], T] { def get(r: Request[Stream]) = (r |! str).map(_.mkString).toSuccess(missing(str).wrapNel) >>= (v => p.read(v).toSuccess(invalid(str).wrapNel)) diff --git a/src/main/scala/sage/package.scala b/src/main/scala/sage/package.scala index cc39a90..34cdcb2 100644 --- a/src/main/scala/sage/package.scala +++ b/src/main/scala/sage/package.scala @@ -1,7 +1,7 @@ import sage.EntityImplicits import scalaz._ import Scalaz._ -import props._ +import hprops._ import metascala.HLists._ @@ -10,4 +10,4 @@ package object sage extends with FunctionWs with FindDSLImplicits with EntityProperties - with PropsDSL + with HPropsDSL diff --git a/src/test/scala/sage/PropertySpec.scala b/src/test/scala/sage/PropertySpec.scala index cf5a525..ca60c31 100644 --- a/src/test/scala/sage/PropertySpec.scala +++ b/src/test/scala/sage/PropertySpec.scala @@ -1,6 +1,6 @@ package sage -import props._ +import hprops._ import scalaz._ import Scalaz._ import org.scalatest._ diff --git a/src/test/scala/sage/RequestSpec.scala b/src/test/scala/sage/RequestSpec.scala index c6d3f2a..ce7b0a3 100644 --- a/src/test/scala/sage/RequestSpec.scala +++ b/src/test/scala/sage/RequestSpec.scala @@ -2,7 +2,7 @@ package sage import metascala.HLists._ -import props._ +import hprops._ import scalaz._ import Scalaz._ diff --git a/src/test/scala/sage/spec1.scala b/src/test/scala/sage/spec1.scala index aae146c..ccb2f22 100644 --- a/src/test/scala/sage/spec1.scala +++ b/src/test/scala/sage/spec1.scala @@ -5,7 +5,7 @@ import metascala.HLists._ import scalaz._ import Scalaz._ -import props._ +import hprops._ import org.scalatest._ import org.scalatest.matchers.ShouldMatchers