I have a class I am trying to use to encapsulate the target for a Results.Unauthorized(...)
call in an ActionRefiner
The current version of the class itself is roughly:
class UnauthorizedTarget @Inject() () {
def raw: String = "Not logged in"
def json: JsValue = Json.toJson(Map("status" -> "unauthorized"))
def template: play.twirl.api.HtmlFormat.Appendable = views.html.index()
def apply() = template
}
used in the following manner
if (x) {
new SkeletonKeyRequest(Option(cookie.value), request)
} else {
Results.Unauthorized(unauthorizedTarget())
}
I’m trying to figure out a good way to generalize this as all three options are valid for Results.Status.apply()
but there may be some type inference that is over my head. Is there a clean way to define a trait similar to:
trait RefinementTarget () {
def raw: String
def json: JsValue
def template: play.twirl.api.HtmlFormat.Appendable
def apply(): X // implementer's choice
Where the apply
method can be one of the other three methods defined during implementation?