mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 13:33:20 +12:00
fix: consider nested entities in ash.formatter
This commit is contained in:
parent
e4af9b8c4c
commit
2a4fc7ebb1
1 changed files with 32 additions and 11 deletions
|
@ -66,28 +66,39 @@ defmodule Mix.Tasks.Ash.Formatter do
|
||||||
defp all_entity_builders(sections) do
|
defp all_entity_builders(sections) do
|
||||||
Enum.flat_map(sections, fn section ->
|
Enum.flat_map(sections, fn section ->
|
||||||
Enum.concat([
|
Enum.concat([
|
||||||
entity_option_builders(section),
|
all_entity_option_builders(section),
|
||||||
section_option_builders(section),
|
section_option_builders(section),
|
||||||
entity_builders(section)
|
section_entity_builders(section)
|
||||||
])
|
])
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp entity_builders(section) do
|
defp section_entity_builders(section) do
|
||||||
Enum.flat_map(section.entities, fn entity ->
|
Enum.flat_map(section.entities, fn entity ->
|
||||||
arg_count = Enum.count(entity.args)
|
entity_builders(entity)
|
||||||
[{entity.name, arg_count}, {entity.name, arg_count + 1}]
|
|
||||||
end) ++ all_entity_builders(section.sections())
|
end) ++ all_entity_builders(section.sections())
|
||||||
end
|
end
|
||||||
|
|
||||||
defp entity_option_builders(section) do
|
defp entity_builders(entity) do
|
||||||
|
arg_count = Enum.count(entity.args)
|
||||||
|
|
||||||
|
[{entity.name, arg_count}, {entity.name, arg_count + 1}] ++
|
||||||
|
flat_map_nested_entities(entity, &entity_builders/1)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp all_entity_option_builders(section) do
|
||||||
Enum.flat_map(section.entities, fn entity ->
|
Enum.flat_map(section.entities, fn entity ->
|
||||||
|
entity_option_builders(entity)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp entity_option_builders(entity) do
|
||||||
entity.schema
|
entity.schema
|
||||||
|> Keyword.drop(entity.args)
|
|> Keyword.drop(entity.args)
|
||||||
|> Enum.map(fn {key, _schema} ->
|
|> Enum.map(fn {key, _schema} ->
|
||||||
{key, 1}
|
{key, 1}
|
||||||
end)
|
end)
|
||||||
end)
|
|> Kernel.++(flat_map_nested_entities(entity, &entity_option_builders/1))
|
||||||
end
|
end
|
||||||
|
|
||||||
defp section_option_builders(section) do
|
defp section_option_builders(section) do
|
||||||
|
@ -95,4 +106,14 @@ defmodule Mix.Tasks.Ash.Formatter do
|
||||||
{key, 1}
|
{key, 1}
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp flat_map_nested_entities(entity, mapper) do
|
||||||
|
Enum.flat_map(entity.entities, fn {_, nested_entities} ->
|
||||||
|
nested_entities
|
||||||
|
|> List.wrap()
|
||||||
|
|> Enum.flat_map(fn nested_entity ->
|
||||||
|
mapper.(nested_entity)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue