mirror of
https://github.com/ash-project/ash.git
synced 2024-09-19 13:03:02 +12:00
improvement: add Ash.Igniter.codegen/2
This commit is contained in:
parent
57d11f65a7
commit
885727fb87
1 changed files with 28 additions and 1 deletions
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue