DiffoExample. Calculations. InheritedCharacteristicViaAssignment
(DiffoExample v0.2.3)
Copy Markdown
View Source
Brings up a typed characteristic value from an assignment-source instance.
Mirrors the shape of Diffo.Provider.Calculations.InheritedPlace and
Diffo.Provider.Calculations.InheritedParty — traverses
AssignmentRelationship by alias to reach source instances, then queries
the typed characteristic resource on each source and returns its .value.
Sibling to InheritedCharacteristicViaRelationship, which performs the
analogous traversal over DefinedSimpleRelationship edges (forward,
source → target). Pick the right calc by the kind of edge being
traversed — assignment vs. relationship.
Local-to-this-repo for now. Worth yarning upstream as a pair of diffo-side DSL declarations backed by analogous calcs in the provider extension, sitting alongside the existing inherited-place and inherited-party machinery.
Options
via:(required) — list of alias atoms naming the assignment chain from this instance back to the source whose characteristic we want. Each step filtersAssignmentRelationshipbytarget_idandalias, then followssource_idto the next set of instances. The aliases are the consumer's name for the upstream related resource at each hop (e.g. AVC names its CVC slot:cvc, CVC names its NniGroup slot:nni_group) — set when the assignment is made.characteristic_module:(required) — the typed characteristic Ash resource on the final source (e.g.ShelfCharacteristic). The calc queries this resource byinstance_idand returns the.value.singular?:(optional, defaultfalse) — whentrue, unwraps the result to a single value (ornil) rather than a list. Safe whenever every hop invia:traverses anAssignmentRelationshipwith identity[:target_id, :alias]— that guarantees ≤1 source per step, so the walk yields at most one value. Declare the calc's return type as:map(rather than{:array, :map}) when using this option.
Example
# Card brings up its shelf's typed characteristic via the slot
# assignment the shelf made to it (alias :slot on the incoming
# AssignmentRelationship).
calculate :shelf, {:array, :map},
{DiffoExample.Calculations.InheritedCharacteristicViaAssignment,
[via: [:slot], characteristic_module: ShelfCharacteristic]}
# Path brings up the same via a two-hop chain — port-then-slot.
calculate :shelf, {:array, :map},
{DiffoExample.Calculations.InheritedCharacteristicViaAssignment,
[via: [:port, :slot], characteristic_module: ShelfCharacteristic]}
# AVC brings up its singular CVC via its :cvc consumer-alias on the
# cvlan assignment from the CVC. AssignmentRelationship identity
# guarantees ≤1 source, so we declare :map and ask the calc to unwrap.
calculate :cvc, :map,
{DiffoExample.Calculations.InheritedCharacteristicViaAssignment,
[via: [:cvc], characteristic_module: CvcCharacteristic, singular?: true]}
Summary
Functions
Callback implementation for Ash.Resource.Calculation.describe/1.
Callback implementation for Ash.Resource.Calculation.has_expression?/0.
Callback implementation for Ash.Resource.Calculation.init/1.
Callback implementation for Ash.Resource.Calculation.strict_loads?/0.
Functions
Callback implementation for Ash.Resource.Calculation.describe/1.
Callback implementation for Ash.Resource.Calculation.has_expression?/0.
Callback implementation for Ash.Resource.Calculation.init/1.
Callback implementation for Ash.Resource.Calculation.strict_loads?/0.