View Source Ash.Filter.Predicate behaviour (ash v3.4.36)
Represents a predicate which can be simplified and/or compared with other predicates
Simplification and comparison will need more documentation, but ultimately it is the logic that allows us to have a flexible and powerful authorization system.
Summary
Callbacks
As long as at least one predicate of the type defined in your module,
(and this callback is implemented), it will be called with all of the
other predicates present in a filter. The return value is relatively
complex, but it should be a list of boolean statements. E.g.
{op, left, right}
and {:not, predicate}
(nested as deep as necessary).
Compare two predicates. If possible, use bulk_compare/1
instead
Simplify to a more primitive statement.
Functions
Checks with each predicate module to see if it has a comparison with
Types
@type comparison() ::
:unknown
| :right_includes_left
| :left_includes_right
| :mutually_inclusive
| :mutually_exclusive
@type predicate() :: struct()
Callbacks
As long as at least one predicate of the type defined in your module,
(and this callback is implemented), it will be called with all of the
other predicates present in a filter. The return value is relatively
complex, but it should be a list of boolean statements. E.g.
{op, left, right}
and {:not, predicate}
(nested as deep as necessary).
The best way to do it is to find lists of predicates that are mutually
exclusive or mutually inclusive, and pass those lists into
Ash.SatSolver.mutually_exclusive/1
and Ash.SatSolver.mutually_inclusive/1
@callback compare(predicate(), predicate()) :: comparison()
Compare two predicates. If possible, use bulk_compare/1
instead
Simplify to a more primitive statement.
For example, x in [1, 2]
simplifies to x == 1 or x == 2
.
Simplifying to filter expressions that already have comparisons
lets you avoid writing that logic for a given predicate.
Functions
Checks with each predicate module to see if it has a comparison with