Skip to content

Instantly share code, notes, and snippets.

@sergiomichels
Created November 28, 2013 16:43
Show Gist options
  • Save sergiomichels/7694753 to your computer and use it in GitHub Desktop.
Save sergiomichels/7694753 to your computer and use it in GitHub Desktop.
Grails script that validates if the class name is a domain class
import grails.util.GrailsNameUtils
includeTargets << grailsScript("_GrailsBootstrap") //https://github.com/grails/grails-core/blob/master/scripts/_GrailsBootstrap.groovy
includeTargets << grailsScript("_GrailsCreateArtifacts") //https://github.com/grails/grails-core/blob/master/scripts/_GrailsCreateArtifacts.groovy
target ('default': 'Validates if the argument is a domain class') {
depends(loadApp)
promptForName(type: type)
for (name in argsMap["params"]) {
name = purgeRedundantArtifactSuffix(name, type)
name = name.indexOf('.') > 0 ? name : GrailsNameUtils.getClassNameRepresentation(name)
def domainClass = grailsApp.getDomainClass(name)
if (!domainClass) {
grailsConsole.updateStatus "Domain class not found in grails-app/domain, trying hibernate mapped classes..."
bootstrap()
domainClass = grailsApp.getDomainClass(name)
}
if (!domainClass) {
event("StatusFinal", ["No domain class found for name ${name}. Please try again and enter a valid domain class name"])
return
}
//do your work here...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment