From 0339c867f30fbe827ab9f49e90812885da080d0f Mon Sep 17 00:00:00 2001 From: Mathieu Decaffmeyer <5883963+mathieuprog@users.noreply.github.com> Date: Mon, 3 Jun 2024 14:08:35 +0800 Subject: [PATCH] Clean --- lib/polymorphic_embed/options_validator.ex | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/polymorphic_embed/options_validator.ex b/lib/polymorphic_embed/options_validator.ex index 806433e..a787865 100644 --- a/lib/polymorphic_embed/options_validator.ex +++ b/lib/polymorphic_embed/options_validator.ex @@ -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." @@ -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