AshCommanded.Commanded.Transformers.GenerateProjectionModules (AshCommanded v0.1.0)
View SourceGenerates projection modules based on the projections defined in the DSL.
For each projection defined in a resource, this transformer will generate a corresponding module that handles the transformation of events into resource updates.
This transformer should run after the event module transformer.
Example
Given a resource with the following projection:
projection :user_registered do
action :create
changes(%{status: :active})
end
This transformer will generate a module like:
defmodule MyApp.Projections.UserRegistered do
@moduledoc "Projection that handles user_registered events"
def apply(event, resource) do
# Apply changes to the resource based on the event
changes = %{status: :active}
Ash.Changeset.for_action(resource, event, :create, changes)
end
end
Summary
Functions
Specifies that this transformer should run after the event module transformer.
Callback implementation for Spark.Dsl.Transformer.after_compile?/0
.
Callback implementation for Spark.Dsl.Transformer.before?/1
.
Builds the module name for a projection.
Builds the AST (Abstract Syntax Tree) for a projection module.
Transforms the DSL state to generate projection modules.
Functions
Specifies that this transformer should run after the event module transformer.
Callback implementation for Spark.Dsl.Transformer.after_compile?/0
.
Callback implementation for Spark.Dsl.Transformer.before?/1
.
Builds the module name for a projection.
Examples
iex> build_projection_module(%Projection{name: :user_registered}, MyApp)
MyApp.Projections.UserRegistered
Builds the AST (Abstract Syntax Tree) for a projection module.
Examples
iex> build_projection_module_ast(%Projection{name: :user_registered, action: :create, changes: %{status: :active}}, "User")
{:__block__, [], [{:@, [...], [{:moduledoc, [...], [...]}]}, ...]}
Transforms the DSL state to generate projection modules.
Examples
iex> transform(dsl_state)
{:ok, updated_dsl_state}