fix: actually use warn_on_empty? config

This commit is contained in:
Zach Daniel 2022-08-01 19:23:16 -04:00
parent 32bab0959d
commit f823e35f7d
3 changed files with 15 additions and 5 deletions

View file

@ -183,6 +183,7 @@ locals_without_parens = [
validate_destination_field?: 1, validate_destination_field?: 1,
violation_message: 1, violation_message: 1,
wait_for: 1, wait_for: 1,
warn_on_empty?: 1,
where: 1, where: 1,
writable?: 1 writable?: 1
] ]

View file

@ -36,6 +36,11 @@ defmodule Ash.Registry do
end end
end end
@spec warn_on_empty?(t()) :: boolean
def warn_on_empty?(registry) do
Extension.get_opt(registry, [:entries], :warn_on_empty?, true, true)
end
@spec api_or_api_and_registry(Ash.Api.t() | {Ash.Api.t(), t()}) :: {t(), t()} @spec api_or_api_and_registry(Ash.Api.t() | {Ash.Api.t(), t()}) :: {t(), t()}
def api_or_api_and_registry({api, registry}), do: {api, registry} def api_or_api_and_registry({api, registry}), do: {api, registry}
def api_or_api_and_registry(api), do: {api, api} def api_or_api_and_registry(api), do: {api, api}

View file

@ -3,12 +3,16 @@ defmodule Ash.Registry.Transformers.WarnOnEmpty do
use Ash.Dsl.Transformer use Ash.Dsl.Transformer
def transform(registry, dsl) do def transform(registry, dsl) do
case Ash.Registry.entries(registry) do if Ash.Registry.warn_on_empty?(registry) do
[] -> case Ash.Registry.entries(registry) do
{:warn, dsl, "#{inspect(registry)} has no entries."} [] ->
{:warn, dsl, "#{inspect(registry)} has no entries."}
_ -> _ ->
{:ok, dsl} {:ok, dsl}
end
else
{:ok, dsl}
end end
end end
end end