Links
Github: GitHub - dderooy/judge_json at v0.1.1-beta
HexDocs: JudgeJson — judge_json v0.1.1
Summary
JudgeJson is an Elixir rule engine where rules are json objects. The judge evaluates a json payload and sees if any rules match.
Rule = condition + action
JudgeJson is storage and action agnostic. Ideally you can store/load rules from a DB and evaluate on incoming json payloads. Handler code can then evaluate rules and action however you like.
Rule engines are great for separating business logic from execution logic.
This was also designed with gui form fills in mind. Longterm I’d like to see if I can get a dynamic phoenix form going to create new rules.
This is a beta release so please let me know if any ideas / improvements. Thanks!
Example
payload
{
"data": {
"person": {
"name": "Lionel",
"last_name": "Messi",
"likes": [
"soccer",
"hot dogs",
"sports"
]
}
},
"rules": [
{
"id": "123456",
"conditions": {
"all": [
{
"path": "/person/name",
"operator": "equal",
"value": "Lionel"
},
{
"path": "/person/last_name",
"operator": "equal",
"value": "Messi"
},
{
"path": "/person/likes",
"operator": "contains",
"value": "soccer"
}
]
},
"action": "collect_signature.exs"
}
]
}
iex> JudgeJson.evaluate(payload)
Returns a list of matched rules