Skip to content

Commit 094defc

Browse files
committed
refactor
1 parent a94a1fd commit 094defc

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

lib/polymorphic_embed.ex

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ defmodule PolymorphicEmbed do
6262

6363
def cast_polymorphic_embed(changeset, field, cast_options \\ [])
6464

65+
# credo:disable-for-next-line
6566
def cast_polymorphic_embed(%Ecto.Changeset{} = changeset, field, cast_options) do
6667
field_options = get_field_options(changeset.data.__struct__, field)
6768

@@ -100,26 +101,23 @@ defmodule PolymorphicEmbed do
100101
{:ok, map} when map == %{} and not array? ->
101102
changeset
102103

103-
{:ok, params_for_field} ->
104-
cond do
105-
array? and is_list(params_for_field) ->
106-
cast_polymorphic_embeds_many(
107-
changeset,
108-
field,
109-
changeset_fun,
110-
params_for_field,
111-
field_options
112-
)
113-
114-
not array? and is_map(params_for_field) ->
115-
cast_polymorphic_embeds_one(
116-
changeset,
117-
field,
118-
changeset_fun,
119-
params_for_field,
120-
field_options
121-
)
122-
end
104+
{:ok, params_for_field} when is_list(params_for_field) and array? ->
105+
cast_polymorphic_embeds_many(
106+
changeset,
107+
field,
108+
changeset_fun,
109+
params_for_field,
110+
field_options
111+
)
112+
113+
{:ok, params_for_field} when is_map(params_for_field) and not array? ->
114+
cast_polymorphic_embeds_one(
115+
changeset,
116+
field,
117+
changeset_fun,
118+
params_for_field,
119+
field_options
120+
)
123121
end
124122
end
125123

0 commit comments

Comments
 (0)