[#5] Minor enhancements

This commit is contained in:
Marcin Zajaczkowski
2015-02-13 00:11:00 +01:00
parent e5d218a2d2
commit 71757e1ec8
9 changed files with 10 additions and 32 deletions

View File

@@ -18,15 +18,13 @@ class GroovyDsl {
}
void request(@DelegatesTo(Request) Closure closure) {
Request request = new Request()
this.request = request
this.request = new Request()
closure.delegate = request
closure()
}
void response(@DelegatesTo(Response) Closure closure) {
Response response = new Response()
this.response = response
this.response = new Response()
closure.delegate = response
closure()
}

View File

@@ -4,9 +4,6 @@ import groovy.transform.CompileStatic
@CompileStatic
class ClientDslProperty extends DslProperty {
ClientDslProperty(Object clientValue, Object serverValue) {
super(clientValue, serverValue) }
ClientDslProperty(Object singleValue) {
super(singleValue)
}

View File

@@ -39,7 +39,7 @@ class Common {
}
DslProperty $(ServerDslProperty server, ClientDslProperty client) {
return value(client, server)
return value(server, client)
}
ClientDslProperty client(Object clientValue) {
@@ -49,5 +49,4 @@ class Common {
ServerDslProperty server(Object serverValue) {
return new ServerDslProperty(serverValue)
}
}

View File

@@ -1,10 +0,0 @@
package io.coderate.accurest.dsl.internal
//TODO: There is problem with a trait usage
class DelegateHelper {
public static <T> void delegateToClosure(@DelegatesTo(T) Closure closure, T delegate) {
closure.delegate = delegate
closure()
}
}

View File

@@ -1,4 +1,5 @@
package io.coderate.accurest.dsl.internal
import groovy.transform.CompileStatic
@CompileStatic

View File

@@ -2,8 +2,6 @@ package io.coderate.accurest.dsl.internal
import groovy.transform.CompileStatic
import groovy.transform.TypeChecked
import static io.coderate.accurest.dsl.internal.DelegateHelper.delegateToClosure
@TypeChecked
class Request extends Common {
@@ -49,9 +47,9 @@ class Request extends Common {
}
void headers(@DelegatesTo(Headers) Closure closure) {
Headers headers = new Headers()
this.headers = headers
delegateToClosure(closure, headers)
this.headers = new Headers()
closure.delegate = headers
closure()
}
void urlPath(String urlPath) {

View File

@@ -3,8 +3,6 @@ package io.coderate.accurest.dsl.internal
import groovy.transform.CompileStatic
import groovy.transform.TypeChecked
import static io.coderate.accurest.dsl.internal.DelegateHelper.delegateToClosure
@TypeChecked
class Response extends Common {
@@ -31,7 +29,8 @@ class Response extends Common {
void headers(@DelegatesTo(Headers) Closure closure) {
this.headers = new Headers()
delegateToClosure(closure, headers)
closure.delegate = headers
closure()
}
void body(Map<String, Object> body) {

View File

@@ -1,12 +1,10 @@
package io.coderate.accurest.dsl.internal
import groovy.transform.CompileStatic
@CompileStatic
class ServerDslProperty extends DslProperty {
ServerDslProperty(Object clientValue, Object serverValue) {
super(clientValue, serverValue) }
ServerDslProperty(Object singleValue) {
super(singleValue)
}

View File

@@ -94,6 +94,4 @@ class WithValuePattern {
void matchesJsonPath(DslProperty matchesJsonPath) {
this.matchesJsonPath = matchesJsonPath
}
}