ash v1.24.1 Ash.Filter.Predicate behaviour View Source

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.

Link to this section Summary

Functions

Checks with each predicate module to see if it has a comparison with

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.

Link to this section Types

Specs

comparison() ::
  :unknown
  | :right_includes_left
  | :left_includes_right
  | :mutually_inclusive
  | :mutually_exclusive

Specs

predicate() :: struct()

Link to this section Functions

Checks with each predicate module to see if it has a comparison with

Link to this section Callbacks

Link to this callback

bulk_compare(list)

View Source (optional)

Specs

bulk_compare([predicate()]) :: term()

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

Link to this callback

compare(predicate, predicate)

View Source (optional)

Specs

compare(predicate(), predicate()) :: comparison()

Compare two predicates. If possible, use bulk_compare/1 instead

Link to this callback

simplify(predicate)

View Source (optional)

Specs

simplify(predicate()) :: term()

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.