Skip to content

Commit

Permalink
chore: credo
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Jan 31, 2024
1 parent 1ef851a commit ae0c8e3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/change_builders/full_diff/full_diff.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ defmodule AshPaperTrail.ChangeBuilders.FullDiff do

defp build_attribute_change(attribute, changeset) do
cond do
is_union?(attribute.type) ->
union?(attribute.type) ->
UnionChange.build(attribute, changeset)

is_embedded?(attribute.type) ->
embedded?(attribute.type) ->
EmbeddedChange.build(attribute, changeset)

true ->
Expand Down
8 changes: 4 additions & 4 deletions lib/change_builders/full_diff/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ defmodule AshPaperTrail.ChangeBuilders.FullDiff.Helpers do
def attribute_change_map({true, data, true, data}), do: %{unchanged: data}
def attribute_change_map({true, data, true, value}), do: %{from: data, to: value}

def is_union?(type) do
def union?(type) do
type == Ash.Type.Union or
(Ash.Type.NewType.new_type?(type) && Ash.Type.NewType.subtype_of(type) == Ash.Type.Union)
end

def is_embedded?(type), do: Ash.Type.embedded_type?(type)
def embedded?(type), do: Ash.Type.embedded_type?(type)

def embedded_union?(type, subtype) do
with true <- is_union?(type),
with true <- union?(type),
true <- :erlang.function_exported(type, :subtype_constraints, 0),
subtype_constraints <- type.subtype_constraints(),
subtypes when not is_nil(subtypes) <- Keyword.get(subtype_constraints, :types),
subtype_config when not is_nil(subtype) <- Keyword.get(subtypes, subtype),
subtype_config_type when not is_nil(subtype_config_type) <-
Keyword.get(subtype_config, :type) do
is_embedded?(subtype_config_type)
embedded?(subtype_config_type)
else
_ -> false
end
Expand Down
4 changes: 2 additions & 2 deletions lib/change_builders/full_diff/list_change.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ defmodule AshPaperTrail.ChangeBuilders.FullDiff.ListChange do
defp dump_array(values, %{type: {:array, attr_type}} = attribute) do
array_type =
cond do
is_union?(attr_type) -> :union
is_embedded?(attr_type) -> :embedded
union?(attr_type) -> :union
embedded?(attr_type) -> :embedded
true -> :simple
end

Expand Down

0 comments on commit ae0c8e3

Please sign in to comment.