From 9326dfd92a9fc120c2cdd892575486193281fb26 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Thu, 26 Jul 2018 10:31:40 +0800 Subject: Simplify public Decorator API --- cask/test/src/test/cask/Decorated.scala | 17 +++++++++++++++++ cask/test/src/test/cask/Decorator.scala | 26 -------------------------- cask/test/src/test/cask/ExampleTests.scala | 2 +- 3 files changed, 18 insertions(+), 27 deletions(-) create mode 100644 cask/test/src/test/cask/Decorated.scala delete mode 100644 cask/test/src/test/cask/Decorator.scala (limited to 'cask/test') diff --git a/cask/test/src/test/cask/Decorated.scala b/cask/test/src/test/cask/Decorated.scala new file mode 100644 index 0000000..94a1ce2 --- /dev/null +++ b/cask/test/src/test/cask/Decorated.scala @@ -0,0 +1,17 @@ +package test.cask +import cask.model.ParamContext + + +object Decorated extends cask.MainRoutes{ + class myDecorator extends cask.Routes.Decorator { + def getParamValues(ctx: ParamContext) = Map("extra" -> 31337) + } + + @myDecorator() + @cask.get("/hello/:world") + def hello(world: String)(extra: Int) = { + world + extra + } + + initialize() +} diff --git a/cask/test/src/test/cask/Decorator.scala b/cask/test/src/test/cask/Decorator.scala deleted file mode 100644 index e8927cf..0000000 --- a/cask/test/src/test/cask/Decorator.scala +++ /dev/null @@ -1,26 +0,0 @@ -package test.cask -import cask.internal.Router.ArgReader -import cask.model.ParamContext - - -object Decorator extends cask.MainRoutes{ - class myDecorator extends cask.main.Routes.Decorator { - type InputType = Int - - def handle(ctx: ParamContext) = Map("extra" -> 31337) - - def parseMethodInput[T] = new ArgReader[Int, T, ParamContext] { - def arity = 1 - - def read(ctx: ParamContext, label: String, input: Int) = input.asInstanceOf[T] - } - } - - @myDecorator() - @cask.get("/hello/:world") - def hello(world: String)(extra: Int) = { - world + extra - } - - initialize() -} diff --git a/cask/test/src/test/cask/ExampleTests.scala b/cask/test/src/test/cask/ExampleTests.scala index be0000c..50e9776 100644 --- a/cask/test/src/test/cask/ExampleTests.scala +++ b/cask/test/src/test/cask/ExampleTests.scala @@ -86,7 +86,7 @@ object ExampleTests extends TestSuite{ ).text() ==> "OK Plain(hello,null) List(1, 2)" } - 'Decorator - test(Decorator){ host => + 'Decorated - test(Decorated){ host => requests.get(host + "/hello/woo").text() ==> "woo31337" } -- cgit v1.2.3