Logic Provider¶
Hooks for various logical operations such as match/case, assert, and while loops.
Hooks¶
Type | Description | Return |
---|---|---|
assert | Hook for asserting an input is equal to a value. | bool |
match | Hook for match / case statements. Takes a dict where the keys are matched to a value. If the case value has an arrow in it (ie key->: ... ) the arrow is stripped away. All matched values are ran as hooks. | Union[list, dict, NoneType] |
raise | Hook for raising an error. | None |
return | Hook for stopping parsing and returning a given value instead of the public context data. For strings it renders the value, for dicts / lists it parses it, for everything else (bool / int) it returns the value as is. | Any |
returns | Hook for stopping parsing and returning a given value instead of the public context data. Returns the value as is without parsing or rendering as compared to the return hook which renders / parses by default. |
Any |
Examples¶
match¶
The match
hook mimics common match/case statements
# Stand in for some kind of thing to match against
selection:
->: select What to do?
choices: ['agree','disagree']
matcher:
->: match selection
case:
agree: Some value
disagree->: # Run some tackle context
...
assert¶
Hook to assert if two items are equal. Can also easily be done with jinja but with this hook you can exit based on the assertion.
stuff: things
assertion->: assert {{stuff}} things # Would exit otherwise
with-jinja->: {{stuff!='things'}} # Equivalent and would not exit
stuff: things
assertion: true
with-jinja: false
type¶
Hook to get type of variable.
stuff: things
map:
stuff: things
stuff_type->: type stuff # rendered by default
map_type->: type map
stuff: things
map:
stuff: things
stuff_type: str
map_type: dict