mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 13:33:20 +12:00
chore: a few small error case improvements
This commit is contained in:
parent
f832ab3624
commit
eb2c2de528
4 changed files with 19 additions and 4 deletions
|
@ -31,7 +31,17 @@ defmodule Ash.CodeInterface do
|
|||
{:argument, argument}
|
||||
end
|
||||
|
||||
if !field.allow_nil? do
|
||||
cond do
|
||||
field.allow_nil? && !(field.name in Map.get(action, :require_attributes, [])) ->
|
||||
:ok
|
||||
|
||||
field.name in Map.get(action, :allow_nil_input, []) ->
|
||||
:ok
|
||||
|
||||
!(field.name in Map.get(action, :accept, [])) ->
|
||||
:ok
|
||||
|
||||
true ->
|
||||
raise "Code interface for #{action.name} has optional argument #{key} but it is not optional"
|
||||
end
|
||||
|
||||
|
|
|
@ -255,6 +255,7 @@ defmodule Ash.Engine do
|
|||
def must_be_local?(request) do
|
||||
[request.resource | request.touches_resources || []]
|
||||
|> Enum.filter(& &1)
|
||||
|> Enum.filter(&is_atom/1)
|
||||
|> Enum.any?(fn resource ->
|
||||
(Ash.DataLayer.data_layer_can?(resource, :transact) &&
|
||||
Ash.DataLayer.in_transaction?(resource)) ||
|
||||
|
|
|
@ -113,6 +113,10 @@ defmodule Ash.Resource do
|
|||
end
|
||||
|
||||
if api = Ash.Resource.Info.define_interface_for(__MODULE__) do
|
||||
if api == __MODULE__ do
|
||||
raise "code_interface.define_for should be set to the API module you want it to call, not the resource."
|
||||
end
|
||||
|
||||
require Ash.CodeInterface
|
||||
Ash.CodeInterface.define_interface(api, __MODULE__)
|
||||
end
|
||||
|
|
|
@ -8,11 +8,11 @@ defmodule Ash.Resource.Interface do
|
|||
|
||||
defmacro __using__(_) do
|
||||
quote bind_quoted: [], generated: true do
|
||||
if Ash.Resource.Info.define_interface_for(__MODULE__) do
|
||||
if define_for = Ash.Resource.Info.define_interface_for(__MODULE__) do
|
||||
require Ash.CodeInterface
|
||||
|
||||
Ash.CodeInterface.define_interface(
|
||||
Ash.Resource.Info.define_interface_for(__MODULE__),
|
||||
define_for,
|
||||
__MODULE__
|
||||
)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue