Groovy for Domain-specific Languages - Second Edition
Existing Groovy DSLs [ 238 ] Inheritance By default, GORM implements inheritance relationships with a table-per-hierarchy. A cla ...
Chapter 9 [ 239 ] The mapping closure is implemented in Grails in a fashion very similar to constraints. The mapping closure is ...
Existing Groovy DSLs [ 240 ] Dynamic finders GORM supports a unique and powerful query function through the use of dynamic finde ...
Chapter 9 [ 241 ] GORM as a DSL We've only scratched the surface of what can be done with GORM and Grails. For a more comprehens ...
Existing Groovy DSLs [ 242 ] The common language of ATDD and BDD revolves around defining behavior in user-centric terms. Whethe ...
Chapter 9 [ 243 ] The following code is a simple Spock specification that tests some of the features of the java.util.Stack clas ...
Existing Groovy DSLs [ 244 ] JUnit The Spock test framework is built on top of the JUnit test framework. If we were to rewrite t ...
Chapter 9 [ 245 ] You can explore this a little yourself by launching a Spock test in the debugger of your favorite IDE. Place a ...
Existing Groovy DSLs [ 246 ] Most importantly, in this chapter, we have seen how all of these projects exploit different Groovy ...
[ 247 ] Building a Builder Builders are a powerful feature of Groovy. The Groovy libraries contain an expanding set of builders ...
Building a Builder [ 248 ] The transition from writing XML or HTML to the GroovyMarkup equivalent is an easy one. To make use of ...
Chapter 10 [ 249 ] The success of building our own builder class by using the Groovy MOP depends largely on understanding the se ...
Building a Builder [ 250 ] The main block of code runs within the scope of the script. Each inline closure is in fact an anonymo ...
Chapter 10 [ 251 ] The root() method creates the initial tree map and inserts a root element into it. We can nest as many levels ...
Building a Builder [ 252 ] } expect: tree == [ root: [ "sub-tree-1": [ "leaf-1": "leaf object 1" ], "sub-tree-2": [ "node-1": [ ...
Chapter 10 [ 253 ] indent-- indent.times {print " "} println "</${name}>" } } This is a simple case that we are using just ...
Building a Builder [ 254 ] then: """<root> <level1> <level2> </level2> </level1> </root>""" ...
Chapter 10 [ 255 ] At this point, we have access to the closure, so we can set its delegate to the builder instance. Now, when t ...
Building a Builder [ 256 ] These methods provide the hooks such that, instead of coding at the MOP level with pretended method i ...
Chapter 10 [ 257 ] indent.times {print " "} println "createNode(${name}, ${value})" indent++ return name } def createNode(name, ...
«
9
10
11
12
13
14
15
16
17
18
»
Free download pdf