Skip to content

Instantly share code, notes, and snippets.

@danveloper
Created December 23, 2012 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danveloper/4362029 to your computer and use it in GitHub Desktop.
Save danveloper/4362029 to your computer and use it in GitHub Desktop.
Rules engine support class for rules engine post
class RulesEngineSupport<E> {
RulesEngine engine
E obj
// Deduce the rule list for a given RulesEngine instance
def getRules() {
def rules = []
engine.class.declaredFields.each {
def field = engine."${it.name}"
if (!it.isSynthetic() && field instanceof Closure && it.name.endsWith("Rule")) {
rules << it.name
}
}
rules
}
def apply() {
rules.each { rule ->
engine."$rule"(obj)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment