Groovy web console

subscribe to the feed Subscribe
to this
site

groovy rules

Published 1 month ago by Ruven
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
 // setup binding
 def binding = new Binding()
 binding.status = 'busy'
 binding.favoriteLang = 'groovy'
 binding.personal = [city:'Lisbon', name:'Joao']
 
 def rules = [
 "status == 'busy' || favoriteLang == 'groovy'",
 "personal.city == 'Lisbon' && personal.name == 'Joao'",
 "personal.city == 'Lisbon' && personal.name == 'Ruven'"
 ]

 // evaluate the scripts
 rules.each { rule ->
   def ret = new GroovyShell(binding).evaluate(rule) // TODO: caching important, memory leaks lurking around otherwise
   println "==============="
   println "rule: $rule"
   println "result: $ret"
} 


return "finished"