summaryrefslogtreecommitdiff
path: root/cask/src/cask/main
diff options
context:
space:
mode:
Diffstat (limited to 'cask/src/cask/main')
-rw-r--r--cask/src/cask/main/Decorators.scala15
-rw-r--r--cask/src/cask/main/Main.scala2
-rw-r--r--cask/src/cask/main/Routes.scala11
3 files changed, 13 insertions, 15 deletions
diff --git a/cask/src/cask/main/Decorators.scala b/cask/src/cask/main/Decorators.scala
index e395d5b..dd445a4 100644
--- a/cask/src/cask/main/Decorators.scala
+++ b/cask/src/cask/main/Decorators.scala
@@ -9,7 +9,7 @@ import cask.model.{Request, Response}
* Annotates a Cask endpoint that returns a HTTP [[Response]]; similar to a
* [[Decorator]] but with additional metadata and capabilities.
*/
-trait Endpoint[InnerReturned] extends BaseEndpoint[InnerReturned] {
+trait Endpoint[InnerReturned, Input] extends BaseEndpoint[InnerReturned, Input] {
type OuterReturned = Router.Result[Response.Raw]
}
@@ -17,7 +17,7 @@ trait Endpoint[InnerReturned] extends BaseEndpoint[InnerReturned] {
* An [[Endpoint]] that may return something else than a HTTP response, e.g.
* a websocket endpoint which may instead return a websocket event handler
*/
-trait BaseEndpoint[InnerReturned] extends BaseDecorator[InnerReturned]{
+trait BaseEndpoint[InnerReturned, Input] extends BaseDecorator[InnerReturned, Input]{
/**
* What is the path that this particular endpoint matches?
*/
@@ -55,10 +55,10 @@ trait BaseEndpoint[InnerReturned] extends BaseDecorator[InnerReturned]{
/**
* A [[Decorator]] that may deal with values other than HTTP [[Response]]s
*/
-trait BaseDecorator[InnerReturned]{
- type Input
+trait BaseDecorator[InnerReturned, Input]{
+ final type InputTypeAlias = Input
type InputParser[T] <: ArgReader[Input, T, Request]
- type Delegate = Map[String, Input] => Router.Result[InnerReturned]
+ final type Delegate = Map[String, Input] => Router.Result[InnerReturned]
type OuterReturned <: Router.Result[Any]
def wrapFunction(ctx: Request, delegate: Delegate): OuterReturned
def getParamParser[T](implicit p: InputParser[T]) = p
@@ -75,10 +75,9 @@ trait BaseDecorator[InnerReturned]{
* to `wrapFunction`, which takes a `Map` representing any additional argument
* lists (if any).
*/
-trait Decorator extends BaseDecorator[Response.Raw]{
+trait Decorator extends BaseDecorator[Response.Raw, Any]{
type OuterReturned = Router.Result[Response.Raw]
- type Input = Any
- type InputParser[T] = NoOpParser[Input, T]
+ type InputParser[T] = NoOpParser[Any, T]
}
class NoOpParser[Input, T] extends ArgReader[Input, T, Request] {
diff --git a/cask/src/cask/main/Main.scala b/cask/src/cask/main/Main.scala
index c3a4ace..1eb2dbc 100644
--- a/cask/src/cask/main/Main.scala
+++ b/cask/src/cask/main/Main.scala
@@ -99,7 +99,7 @@ abstract class BaseMain{
)
case Nil =>
- metadata.endpoint.wrapFunction(ctx, endpointBindings =>
+ metadata.endpoint.wrapFunction(ctx, (endpointBindings: Map[String, Any]) =>
metadata.entryPoint
.asInstanceOf[EntryPoint[cask.main.Routes, cask.model.Request]]
.invoke(
diff --git a/cask/src/cask/main/Routes.scala b/cask/src/cask/main/Routes.scala
index 5b02542..ea9d6fe 100644
--- a/cask/src/cask/main/Routes.scala
+++ b/cask/src/cask/main/Routes.scala
@@ -8,7 +8,7 @@ import language.experimental.macros
object Routes{
case class EndpointMetadata[T](decorators: Seq[Decorator],
- endpoint: BaseEndpoint[_],
+ endpoint: BaseEndpoint[_, _],
entryPoint: EntryPoint[T, _])
case class RoutesEndpointsMetadata[T](value: EndpointMetadata[T]*)
object RoutesEndpointsMetadata{
@@ -19,15 +19,15 @@ object Routes{
val routeParts = for{
m <- c.weakTypeOf[T].members
- val annotations = m.annotations.filter(_.tree.tpe <:< c.weakTypeOf[BaseDecorator[_]]).reverse
+ val annotations = m.annotations.filter(_.tree.tpe <:< c.weakTypeOf[BaseDecorator[_, _]]).reverse
if annotations.nonEmpty
} yield {
- if(!(annotations.head.tree.tpe <:< weakTypeOf[BaseEndpoint[_]])) c.abort(
+ if(!(annotations.head.tree.tpe <:< weakTypeOf[BaseEndpoint[_, _]])) c.abort(
annotations.head.tree.pos,
s"Last annotation applied to a function must be an instance of Endpoint, " +
s"not ${annotations.head.tree.tpe}"
)
- val allEndpoints = annotations.filter(_.tree.tpe <:< weakTypeOf[BaseEndpoint[_]])
+ val allEndpoints = annotations.filter(_.tree.tpe <:< weakTypeOf[BaseEndpoint[_, _]])
if(allEndpoints.length > 1) c.abort(
annotations.head.tree.pos,
s"You can only apply one Endpoint annotation to a function, not " +
@@ -45,8 +45,7 @@ object Routes{
q"${annotObjectSyms.head}.convertToResultType",
tq"cask.Request",
annotObjectSyms.map(annotObjectSym => q"$annotObjectSym.getParamParser"),
- annotObjectSyms.map(annotObjectSym => tq"$annotObjectSym.Input")
-
+ annotObjectSyms.map(annotObjectSym => tq"$annotObjectSym.InputTypeAlias")
)
val declarations =