Created
December 23, 2012 04:52
-
-
Save danveloper/4362029 to your computer and use it in GitHub Desktop.
Rules engine support class for rules engine post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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