DiffoExample.Calculations.InheritedCharacteristic (DiffoExample v0.2.2)

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.

Local-to-this-repo for now. Worth yarning upstream as a diffo-side inherited_characteristic DSL declaration backed by a Diffo.Provider.Calculations.InheritedCharacteristic calc, 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 filters AssignmentRelationship by target_id and alias, then follows source_id to the next set of instances. The aliases are the assignee's slot names, supplied 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 by instance_id and returns the .value.

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, :map,
          {DiffoExample.Calculations.InheritedCharacteristic,
           [via: [:slot], characteristic_module: ShelfCharacteristic]}

# Path brings up the same via a two-hop chain — port-then-slot.
calculate :shelf, :map,
          {DiffoExample.Calculations.InheritedCharacteristic,
           [via: [:port, :slot], characteristic_module: ShelfCharacteristic]}

Summary

Functions

describe(opts)

Callback implementation for Ash.Resource.Calculation.describe/1.

has_calculate?()

has_expression?()

Callback implementation for Ash.Resource.Calculation.has_expression?/0.

init(opts)

Callback implementation for Ash.Resource.Calculation.init/1.

strict_loads?()

Callback implementation for Ash.Resource.Calculation.strict_loads?/0.