Groovy for Domain-specific Languages - Second Edition
Implementing a Rules DSL [ 278 ] This will output the string Hello, World! to the console. In other words, we have managed to in ...
Chapter 11 [ 279 ] We can implement this structure by adding two closures to the binding called block and nestedBlock. The block ...
Implementing a Rules DSL [ 280 ] By adding an enclosing property to the block and nestedBlock closures, we ensure that nestedBlo ...
Chapter 11 [ 281 ] This outputs: first block encountered first nested encountered second block encountered second nested encount ...
Implementing a Rules DSL [ 282 ] Here we declare two named closures: setup and teardown. We can now provide default implementati ...
Chapter 11 [ 283 ] The only word of caution to heed is that while using both this style of block and the previous in a single DS ...
Implementing a Rules DSL [ 284 ] assert account.balance == 100.00 def shell = new GroovyShell(binding) shell.evaluate( """ rewar ...
Chapter 11 [ 285 ] } binding.innerBlock = { closure -> closure.delegate = delegate closure() println "innerBlock: " + binding ...
Implementing a Rules DSL [ 286 ] We know that closures and methods in Groovy will return a value even when no return statement i ...
Chapter 11 [ 287 ] Marketers constantly devise new ways to promote products and services to customers, but often the problem is ...
Implementing a Rules DSL [ 288 ] Roughly speaking, an access point equates to 10 cents in value, so basic subscribers are benefi ...
Chapter 11 [ 289 ] Reward types We are in the business of encouraging the subscriber to continue to consume content out of plan ...
Implementing a Rules DSL [ 290 ] Based on these requirements, and with an understanding of how we can structure a DSL using clos ...
Chapter 11 [ 291 ] Ideally, we want to have a single condition in each block, so we need to allow multiple blocks, and provide a ...
Implementing a Rules DSL [ 292 ] if (binding.useAnd) binding.result = (closure() && binding.result) else binding.result ...
Chapter 11 [ 293 ] binding.result = (storeResult || binding.result) } binding.and = storeAnd } This gives us a very flexible con ...
Implementing a Rules DSL [ 294 ] } anyOf { condition { false } condition { true } } } assert result == true } Handling events – ...
Chapter 11 [ 295 ] ... } ... } onUpgrade = { ... } By using this structure for the DSL, the loading and evaluating of the script ...
Implementing a Rules DSL [ 296 ] In the preceding snippet, the evaluate method of the DSL script will set saved to be the closur ...
Chapter 11 [ 297 ] We implement the extend action through a method call on the BroadbandPlus service. The points action is just ...
«
11
12
13
14
15
16
17
18
19
20
»
Free download pdf