Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reuse existing type declarations

  • Loading branch information...
commit 117d484e1025e38eca48366105be485b4a75f729 1 parent d5cb28d
@casualjim casualjim authored
View
2  auth/src/main/scala/org/scalatra/auth/Scentry.scala
@@ -54,7 +54,7 @@ class Scentry[UserType <: AnyRef](
}
//def session = app.session
- def params: MultiMapHeadView[String, String] with MapWithIndifferentAccess[String] = app.params
+ def params: Params = app.params
def redirect(uri: String) { app.redirect(uri) }
def register(strategy: => ScentryStrategy[UserType]) {
View
4 core/src/main/scala/org/scalatra/ScalatraBase.scala
@@ -327,7 +327,7 @@ trait ScalatraSyntax extends CoreDsl with RequestResponseScope with Initializabl
* Assumes that there is never a null or empty value in multiParams. The servlet container won't put them
* in request.getParameters, and we shouldn't either.
*/
- protected val _params: ParamsType = new MultiMapHeadView[String, String] with MapWithIndifferentAccess[String] {
+ protected val _params: Params = new MultiMapHeadView[String, String] with MapWithIndifferentAccess[String] {
protected def multiMap = multiParams
}
@@ -335,7 +335,7 @@ trait ScalatraSyntax extends CoreDsl with RequestResponseScope with Initializabl
* A view of `multiParams`. Returns the head element for any known param,
* and is undefined for any unknown param. Invalid outside `handle`.
*/
- def params: ParamsType = _params
+ def params: Params = _params
/**
* Pluggable way to convert a path expression to a route matcher.
View
4 core/src/main/scala/org/scalatra/package.scala
@@ -1,5 +1,7 @@
package org
+import scalatra.util.{MapWithIndifferentAccess, MultiMapHeadView}
+
package object scalatra
extends Control // make halt and pass visible to helpers outside the DSL
// with DefaultValues // make defaults visible
@@ -10,6 +12,8 @@ package object scalatra
type MultiParams = MultiMap
+ type Params = MultiMapHeadView[String, String] with MapWithIndifferentAccess[String]
+
type Action = () => Any
type ErrorHandler = PartialFunction[Throwable, Any]
View
11 core/src/main/scala/org/scalatra/params.scala
@@ -11,10 +11,7 @@ trait ScalatraParamsImplicits {
self: DefaultImplicitConversions =>
- type ParamsType = MultiMapHeadView[String, String] with MapWithIndifferentAccess[String]
- type MultiParamsType = MultiMap
-
- sealed class TypedParams(params: ParamsType) {
+ sealed class TypedParams(params: Params) {
def getAs[T <: Any](name: String)(implicit tc: TypeConverter[String, T]): Option[T] = params.get(name).flatMap(tc.apply(_))
@@ -22,7 +19,7 @@ trait ScalatraParamsImplicits {
}
- sealed class TypedMultiParams(multiParams: MultiParamsType) {
+ sealed class TypedMultiParams(multiParams: MultiParams) {
def getAs[T <: Any](name: String)(implicit tc: TypeConverter[String, T]): Option[Seq[T]] = multiParams.get(name) map {
s =>
@@ -32,9 +29,9 @@ trait ScalatraParamsImplicits {
def getAs[T <: Date](nameAndFormat: (String, String)): Option[Seq[Date]] = getAs(nameAndFormat._1)(stringToDate(nameAndFormat._2))
}
- implicit def toTypedParams(params: ParamsType) = new TypedParams(params)
+ implicit def toTypedParams(params: Params) = new TypedParams(params)
- implicit def toTypedMultiParams(params: MultiParamsType) = new TypedMultiParams(params)
+ implicit def toTypedMultiParams(params: MultiParams) = new TypedMultiParams(params)
}
object ScalatraParamsImplicits extends ScalatraParamsImplicits with DefaultImplicitConversions
View
14 core/src/test/scala/org/scalatra/ParamsExtensionSpec.scala
@@ -10,9 +10,7 @@ class ParamsExtensionSpec extends Specification {
import ScalatraParamsImplicits._
- case class FakeParams(params: Map[String, String]) extends MultiMapHeadView[String, String]
-
- with MapWithIndifferentAccess[String] {
+ case class FakeParams(params: Map[String, String]) extends MultiMapHeadView[String, String] with MapWithIndifferentAccess[String] {
protected def multiMap = MultiMap(params.map(e => (e._1, List(e._2).toSeq)))
}
@@ -20,7 +18,7 @@ class ParamsExtensionSpec extends Specification {
"add a getAs[T] method to Scalatra Params that returns Option[T]" in {
- val params: ParamsType = FakeParams(Map("a" -> "1", "b" -> "", "c" -> null))
+ val params: Params = FakeParams(Map("a" -> "1", "b" -> "", "c" -> null))
params.getAs[Int]("a") must beSome(1)
@@ -34,7 +32,7 @@ class ParamsExtensionSpec extends Specification {
val (format, dateAsText) = ("dd/MM/yyyy", "9/11/2001")
- val params: ParamsType = FakeParams(Map("TwinTowers" -> dateAsText))
+ val params: Params = FakeParams(Map("TwinTowers" -> dateAsText))
val expectedDate = new SimpleDateFormat(format).parse(dateAsText)
@@ -43,7 +41,7 @@ class ParamsExtensionSpec extends Specification {
}
"return None if a conversion is invalid" in {
- val params: ParamsType = FakeParams(Map("a" -> "hello world"))
+ val params: Params = FakeParams(Map("a" -> "hello world"))
params.getAs[Int]("a") must beNone
}
@@ -53,7 +51,7 @@ class ParamsExtensionSpec extends Specification {
implicit val bogusConverter: TypeConverter[String, Bogus] = (s: String) => Some(Bogus(s))
- val params: ParamsType = FakeParams(Map("a" -> "buffybuffy"))
+ val params: Params = FakeParams(Map("a" -> "buffybuffy"))
params.getAs[Bogus]("a") must beSome
@@ -63,7 +61,7 @@ class ParamsExtensionSpec extends Specification {
"explicitely receive a custom TypeConverter" in {
- val params: ParamsType = FakeParams(Map("a" -> "buffybuffy"))
+ val params: Params = FakeParams(Map("a" -> "buffybuffy"))
params.getAs[Bogus]("a")((s: String) => Some(Bogus(s.toUpperCase))) must beSome(Bogus("BUFFYBUFFY"))
Please sign in to comment.
Something went wrong with that request. Please try again.