Groovy for Domain-specific Languages - Second Edition
Implementing a Rules DSL [ 298 ] grant { extend 1 } } } onPurchase = { reward ( "Earn 10% bonus points on all games." ) { condit ...
Chapter 11 [ 299 ] RewardService provides three event hook methods: applyRewardsOnConsume, applyRewardsOnPurchase, and applyRewa ...
Implementing a Rules DSL [ 300 ] binding.allOf = { closure -> closure.delegate = delegate def storeResult = binding.result de ...
Chapter 11 [ 301 ] binding.points = { points -> def bbPlus = new BroadbandPlus() binding.account.points += points } } void pr ...
Implementing a Rules DSL [ 302 ] GroovyShell shell = new GroovyShell(binding) shell.evaluate("on_purchase.delegate = this;onPurc ...
Chapter 11 [ 303 ] Date getMediaExpiry(media) { if(mediaList[media] != null) { return mediaList[media] } } } The Media class is ...
Implementing a Rules DSL [ 304 ] if (account.mediaList[media.title] == null) { def now = new Date() account.points -= media.poin ...
Chapter 11 [ 305 ] In the setup method, we create an account object with a BASIC plan. We set up four different media objects, a ...
Implementing a Rules DSL [ 306 ] then: account.points == expected when: bbPlus.consume(account, terminator) then: account.points ...
Chapter 11 [ 307 ] account.points == 350 when: bbPlus.upgrade(account, "PREMIUM") then: "Should have 550 for PREMIUM and 100 bon ...
Implementing a Rules DSL [ 308 ] Changing the onConsume reward script fixes this anomaly. Running our tests again will show them ...
[ 309 ] Integrating It All In this final chapter, we will build a fully functioning DSL and integrate it into a web application. ...
Integrating It All [ 310 ] The club was teaching a Java class to the more senior students who had already graduated from Scratch ...
Chapter 12 [ 311 ] Hiding complexity Overall, what we found was that, by hiding some of the complexity inside a runtime environm ...
Integrating It All [ 312 ] Grid.playCorner grid, this.player else Grid.playRandomCell grid, this.player } } } class EoghanPlayer ...
Chapter 12 [ 313 ] So this chapter is a response to that need. It's been coded part-time over a period of a few weeks. What I'll ...
Integrating It All [ 314 ] Events are received by the game server and dispatched to the game engine code, which is generated fro ...
Chapter 12 [ 315 ] event: "select_players" playerX = event.playerX playerO = event.playerO page = "roundX" event: "play_round" d ...
Integrating It All [ 316 ] This particular game engine also has the concept of automated player bots built in. The code in the e ...
Chapter 12 [ 317 ] Each event method takes an optional event parameter and an optional saved session parameter. The type expecte ...
«
11
12
13
14
15
16
17
18
19
20
»
Free download pdf