Possible to add notifier to a resource from an extension on another resource?

Is it possible to dynamically (at compile time) add a notifier to a resource, from within the transformer of an extension on another resource?
10 Replies
ZachDaniel
ZachDaniel2y ago
It’s not possible to alter one resource from another, generally speaking
Alan Heywood
Alan HeywoodOP2y ago
Thanks, i think i can include another extension on the other resources that introspects the primary resource to decide whether to add the notifiers
ZachDaniel
ZachDaniel2y ago
You might run into trouble with that one also honestly
Alan Heywood
Alan HeywoodOP2y ago
Order of compilation issues?
ZachDaniel
ZachDaniel2y ago
Yep. What I’d suggest: write a registry extension that validates that the extension is on any required resources Since the registry compiles after all resources in the registry.
Alan Heywood
Alan HeywoodOP2y ago
Cool, I will look into this. I’m cooking up a way to very easily cache complex complex calculations to database attributes.
ZachDaniel
ZachDaniel2y ago
Actually I may have made a change recently that makes that problematic 🥲 this was changed to a verifier but it should be a transformer https://github.com/ash-project/ash/blob/main/lib/ash/registry/extensions/resource_validations/verifiers/ensure_resources_compiled.ex
GitHub
ash/ensure_resources_compiled.ex at main · ash-project/ash
A declarative and extensible framework for building Elixir applications. - ash/ensure_resources_compiled.ex at main · ash-project/ash
ZachDaniel
ZachDaniel2y ago
The other way to do it is to list which resources must have the extension in compile time config. One resource validates that the compile time config includes it, and the registry extension ensures that each resource in the compile time config that is in the registry (after ensuring they are compiled using https://hexdocs.pm/elixir/1.12/Code.html#ensure_compiled!/1) also uses that extension.
Alan Heywood
Alan HeywoodOP2y ago
Thanks for the info! Will have a crack at it tomorrow I've decided to be pragmatic with this – I will add my extension to each resource that is involved, and add the config via dsl that each resource needs, rather than trying to add all config to one resource and have others read it. This approach means there will be no compilation order issues.
ZachDaniel
ZachDaniel2y ago
👍 sounds like a prudent idea I've been around exactly that same block

Did you find this page helpful?