Skip to content

Commit

Permalink
tidying deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddenton committed May 27, 2019
1 parent 52dc266 commit b0c46bd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,58 +18,42 @@ object ResponseContentMagnet {
/**
* Convert Buf to a ResponseBuilderMagnet for building responses
*/
implicit def bufToMagnet[T](s: Buf): ResponseContentMagnet[T] = new ResponseContentMagnet[T] {
override def apply(b: ResponseBuilder[T]) = b.withContent(s)
}
implicit def bufToMagnet[T](s: Buf): ResponseContentMagnet[T] = (b: ResponseBuilder[T]) => b.withContent(s)

/**
* Convert OutputStream writing function to a ResponseBuilderMagnet for building responses
*/
implicit def outputStreamToMagnet[T](f: OutputStream => Unit): ResponseContentMagnet[T] = new ResponseContentMagnet[T] {
override def apply(b: ResponseBuilder[T]) = b.withContent(f)
}
implicit def outputStreamToMagnet[T](f: OutputStream => Unit): ResponseContentMagnet[T] = (b: ResponseBuilder[T]) => b.withContent(f)

/**
* Convert ChannelBuffer to a ResponseBuilderMagnet for building responses
*/
implicit def channelBufferToMagnet[T](bytebuf: ByteBuf): ResponseContentMagnet[T] = new ResponseContentMagnet[T] {
override def apply(b: ResponseBuilder[T]) = b.withContent(bytebuf)
}
implicit def channelBufferToMagnet[T](bytebuf: ByteBuf): ResponseContentMagnet[T] = (b: ResponseBuilder[T]) => b.withContent(bytebuf)

/**
* Convert AsyncStream to a ResponseBuilderMagnet for building responses
*/
implicit def streamToMagnet[T](stream: AsyncStream[T]): ResponseContentMagnet[T] = new ResponseContentMagnet[T] {
override def apply(b: ResponseBuilder[T]) = b.withContent(stream)
}
implicit def streamToMagnet[T](stream: AsyncStream[T]): ResponseContentMagnet[T] = (b: ResponseBuilder[T]) => b.withContent(stream)

/**
* Convert Reader to a ResponseBuilderMagnet for building responses
*/
implicit def readerToMagnet[T](reader: Reader[Buf]): ResponseContentMagnet[T] = new ResponseContentMagnet[T] {
override def apply(b: ResponseBuilder[T]) = b.withContent(reader)
}
implicit def readerToMagnet[T](reader: Reader[Buf]): ResponseContentMagnet[T] = (b: ResponseBuilder[T]) => b.withContent(reader)

/**
* Convert a custom format type (eg. JsonObject) to a ResponseBuilderMagnet for building responses
*/
implicit def customFormatToMagnet[T](t: T): ResponseContentMagnet[T] = new ResponseContentMagnet[T] {
override def apply(b: ResponseBuilder[T]) = b.withContent(t)
}
implicit def customFormatToMagnet[T](t: T): ResponseContentMagnet[T] = (b: ResponseBuilder[T]) => b.withContent(t)

/**
* Convert String to a ResponseBuilderMagnet for building responses
*/
implicit def stringToMagnet[T](s: String): ResponseContentMagnet[T] = new ResponseContentMagnet[T] {
override def apply(b: ResponseBuilder[T]) = if(b.response.status.code < 400) b.withContent(s) else b.withErrorMessage(s)
}
implicit def stringToMagnet[T](s: String): ResponseContentMagnet[T] = (b: ResponseBuilder[T]) => if (b.response.status.code < 400) b.withContent(s) else b.withErrorMessage(s)

/**
* Convert an Exception to a ResponseBuilderMagnet for building responses
*/
implicit def exceptionToMagnet[T](error: Throwable): ResponseContentMagnet[T] = new ResponseContentMagnet[T] {
override def apply(b: ResponseBuilder[T]) = b.withError(error)
}
implicit def exceptionToMagnet[T](error: Throwable): ResponseContentMagnet[T] = (b: ResponseBuilder[T]) => b.withError(error)
}


Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MultipartFileTest extends FunSpec with Matchers {
describe("OnDiskMultiPartFile") {
it("converts toFileElement") {
val tempFile = File.createTempFile("temp", "file")
Files.write("hello bob", tempFile, UTF_8)
Files.asCharSink(tempFile, UTF_8).write("hello bob")
tempFile.deleteOnExit()
Bufs.asUtf8String(OnDiskMultiPartFile("file", tempFile, None).toFileElement("hello").content) shouldBe "hello bob"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.lang.reflect.{Field, Method}
import com.github.mustachejava.Iteration
import com.github.mustachejava.reflect.ReflectionObjectHandler

import scala.collection.JavaConversions.mapAsJavaMap
import scala.collection.JavaConverters
import scala.reflect.ClassTag
import scala.runtime.BoxedUnit

Expand All @@ -17,7 +17,7 @@ class ScalaObjectHandler extends ReflectionObjectHandler {
override def checkField(member: Field) {}

override def coerce(value: AnyRef) = value match {
case m: collection.Map[_, _] => mapAsJavaMap(m)
case m: collection.Map[_, _] => JavaConverters.mapAsJavaMap(m)
case _: BoxedUnit => null
case Some(some: AnyRef) => coerce(some)
case None => null
Expand Down

0 comments on commit b0c46bd

Please sign in to comment.