Skip to content

Instantly share code, notes, and snippets.

@bostonaholic
Created June 17, 2011 02:47
Show Gist options
  • Save bostonaholic/1030763 to your computer and use it in GitHub Desktop.
Save bostonaholic/1030763 to your computer and use it in GitHub Desktop.
meta programming in groovy
def isDetailCancellableWithDelegate = {
delegate.status != "INVOICED" || billingService.isCancellable(delegate.invoice)
}
def theMetaProgrammingWay = {
def listOfObjects = detailService.findAll()
listOfObjects.each {
it.metaClass.isCancellable = isDetailCancellableWithDelegate
}
listOfObjects
}
/*****************************************************/
def isDetailCancellableNormal(def it) {
it.status != "INVOICED" || billingService.isCancellable(it.invoice)
}
def the_Normal_Way = {
def listOfObjects = detailService.findAll()
def listOfMaps = []
listOfObjects.each {
def props = it.properties
props.isCancellable = isDetailCancellableNormal(props)
listOfMaps.add props
}
listOfMaps
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment