-
Notifications
You must be signed in to change notification settings - Fork 10
Rule and function scripts
There are two kinds of files that can be defined in a grules DSL:
Rules script — a script that contains specification of preprocessing rules that must be applied to incoming data. The main purpose of a rules script is to ensure that all external values have been properly preformatted and sanitized before updating an application model. Subsequently, after the input is processed by a rules script it may be considered clean.
Functions script — a class that defines validation and conversion functions used by the rules scripts.
To be evaluated as a rules script, the file name must end with the suffix Grules. As a functions script you can specify any Java or Groovy class with static methods. For convenience, you can use the class-level @Functions
annotation, which adds the static modifier to all class methods at compile time, for example:
@Functions
class StringFunctions {
String trim(String value) {
value.trim()
}
String contains(String value, String text) {
value.contains(text)
}
}