Skip to content

Instantly share code, notes, and snippets.

@beckje01
Created July 28, 2014 08:49
Show Gist options
  • Save beckje01/136fce42cdba7036a988 to your computer and use it in GitHub Desktop.
Save beckje01/136fce42cdba7036a988 to your computer and use it in GitHub Desktop.
Ratpack Context Examples
@Grab('io.ratpack:ratpack-groovy:0.9.6')
import ratpack.registry.RegistrySpec
import static ratpack.groovy.Groovy.*
import static ratpack.registry.Registries.registry
ratpack {
handlers {
handler {
request.register(Person.class, new Person(name: "Test"))
next()
}
handler {
next(registry({ RegistrySpec registrySpec ->
registrySpec.add(Foo.class, new Foo(value: "fooValue"))
def people = []
people.add(new Person(name: "PersonList1"))
people.add(new Person(name: "PersonList2"))
registrySpec.add(PersonList, people)
}))
}
get { Person p ->
def people = maybeGet(PersonList.class)
render "Hello ${p.name}, ${people?.size()}"
}
}
}
class Person {
String name
}
class PersonList extends ArrayList<Person> {
}
class Foo {
String value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment