Getting Started
Install RuleBox and see what it registers in WireBox.
Getting Started
Requirements
- BoxLang 1.18+
- ColdBox 8+
Installation
Leverage CommandBox to install
RuleBox as a module in your ColdBox application. It installs into your
app's modules/ folder:
box install rulebox
Optional modules
Rules written in BoxLang or JSON need nothing else. Two features rely on official BoxLang modules that RuleBox does not install for you, so install them only if you use them:
| Feature | Install |
|---|---|
YAML rule files (YAMLRuleSource, or .yaml/.yml files in the convention folder) | box install bx-yaml |
Visualizer metrics that survive a restart (SQLiteMetricsStore) | box install bx-sqlite, plus a datasource. See Rule Visualizer. |
Your first rule
Save this as models/HelloWorld.bx:
class extends="rulebox.models.RuleBook"{
function defineRules(){
addRule( newRule( "greet" )
.then( ( facts, result ) => result.setValue( "Hello " & facts.name ) ) )
}
}
Then run it from a handler or anywhere you can call getInstance():
getInstance( "HelloWorld" )
.run( { name: "World" } )
.getResult()
.getValue()
That returns Hello World. run() takes your facts, getResult() gets the
result, and getValue() reads what the rule put in it. To go deeper, see
Defining RuleBooks.
What gets registered
Once installed, the module registers the following objects in WireBox:
| WireBox ID | Type | Description |
|---|---|---|
Rule@rulebox | Transient | A single rule |
RuleBook@rulebox | Transient | A rule book that groups and chains rules |
Builder@rulebox | Singleton | Builds à la carte rules and rule books |
Result@rulebox | Transient | Models the result produced by a rule chain |
RuleBookRegistry@rulebox | Singleton | Hands out named rulebooks declared in settings or config files |
RuleBookandRuleare transient objects - they carry state (facts, results, audit trail) across arun(), so a fresh instance is requested every time viagetInstance(). See Thread Safety for why that matters.
Next steps
Need help beyond the docs? See Help and Consulting for professional support from the Ortus Solutions team.