improvement: add Ash.Igniter.codegen/2

This commit is contained in:
Zach Daniel 2024-07-08 15:58:47 -04:00
parent 57d11f65a7
commit 885727fb87

View file

@ -1,5 +1,32 @@
defmodule Ash.Igniter do
@moduledoc false
@moduledoc "Codemods and utilities for working with Ash & Igniter"
@doc "Adds a codegen task, or updates the name to be `<old_name>_and_name`"
def codegen(igniter, name) do
has_codegen? =
Enum.any?(igniter.tasks, fn
{"ash.codegen", _args} ->
true
_ ->
false
end)
if has_codegen? do
Map.update!(igniter, :tasks, fn tasks ->
Enum.map(tasks, fn
{"ash.codegen", [old_name | rest]} ->
{"ash.codegen", [old_name <> "_and_#{name}" | rest]}
task ->
task
end)
end)
else
Igniter.add_task(igniter, "ash.codegen", [name])
end
end
def csv_option(options, key, modifier \\ & &1) do
Keyword.update(
options,