Skip to content

Commit

Permalink
Clean
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuprog committed Jun 3, 2024
1 parent 744912e commit 0339c86
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/polymorphic_embed/options_validator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ defmodule PolymorphicEmbed.OptionsValidator do
@valid_on_type_not_found_options [:raise, :changeset_error, :nilify, :ignore]

def validate!(options) do
keys = Keyword.keys(options)
key_count = keys |> Enum.count()
unique_key_count = Enum.uniq(keys) |> Enum.count()

if key_count != unique_key_count do
raise "Duplicate keys found in options for polymorphic embed."
end

unless Keyword.fetch!(options, :on_replace) in @valid_on_replace_options do
raise(
"`:on_replace` must be set to `:update` for a single polymorphic embed or `:delete` for a list of polymorphic embeds."
Expand Down Expand Up @@ -60,6 +52,14 @@ defmodule PolymorphicEmbed.OptionsValidator do
raise "`:retain_unlisted_types_on_load` must be a list of types as atoms."
end

keys = Keyword.keys(options)
key_count = keys |> Enum.count()
unique_key_count = Enum.uniq(keys) |> Enum.count()

if key_count != unique_key_count do
raise "Duplicate keys found in options for polymorphic embed."
end

unknown_options = Keyword.drop(options, @known_options_names)

if length(unknown_options) > 0 do
Expand Down

0 comments on commit 0339c86

Please sign in to comment.