Spark DSL transformer that generates CanPerform calculations from DSL entities.
This transformer reads can_perform entities and the can_perform_actions
option from the ash_grant section and adds corresponding boolean calculations
using Ash.Resource.Builder.add_new_calculation/5.
Usage Rules
can_perform_actions(batch) andcan_perform(individual entity) can coexist. Both are merged into a single list before generating calculations.- Naming:
can_perform_actions [:update]generates:can_update?.can_perform :updatealso generates:can_update?by default. Use thename:option oncan_performfor a custom name (e.g.,name: :editable?). - Duplicate handling: Uses
add_new_calculation(notadd_calculation), so if the same calculation name already exists (from an explicitcalculationsblock or a duplicate DSL entry), it is silently skipped. The first definition wins. - Coexistence with explicit module: DSL-generated calculations and manually declared
{AshGrant.Calculation.CanPerform, ...}calculations coexist safely. - Resource auto-detection: The transformer injects the resource module automatically
via
Transformer.get_persisted(dsl_state, :module), so users do not need to passresource: __MODULE__when using the DSL. - Public by default: All DSL-generated calculations are
public?: trueby default. Thecan_performentity supportspublic?: falsefor private calculations. - Action validation: At compile time, the transformer verifies that each referenced
action name exists on the resource. A typo like
can_perform_actions [:foobar]raises aSpark.Error.DslErrorwith the list of available actions.
Summary
Functions
Callback implementation for Spark.Dsl.Transformer.after_compile?/0.
Functions
Callback implementation for Spark.Dsl.Transformer.after_compile?/0.