From aac48a0006cf2bb5b9ee62a33a6c1880eee8700e Mon Sep 17 00:00:00 2001 From: Enzo Date: Mon, 24 Mar 2025 15:20:47 +0100 Subject: [PATCH 1/2] avoid compilation warning --- lib/cloak_ecto/migrator/cursor_stream.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cloak_ecto/migrator/cursor_stream.ex b/lib/cloak_ecto/migrator/cursor_stream.ex index 384d586..5813d0f 100644 --- a/lib/cloak_ecto/migrator/cursor_stream.ex +++ b/lib/cloak_ecto/migrator/cursor_stream.ex @@ -77,7 +77,7 @@ defmodule Cloak.Ecto.Migrator.CursorStream do defp fields_for_cursor(schema, primary_key) do if function_exported?(schema, :__cloak_cursor_fields__, 0) do - schema.__cloak_cursor_fields__ + schema.__cloak_cursor_fields__() else [primary_key] end From 8a96604f8d38ac510de0f28c6a5269bb806018dd Mon Sep 17 00:00:00 2001 From: Enzo Date: Mon, 24 Mar 2025 15:26:21 +0100 Subject: [PATCH 2/2] add `:default_vault` configuration --- lib/cloak_ecto/type.ex | 10 +++++++++- lib/cloak_ecto/types/binary.ex | 3 ++- lib/cloak_ecto/types/date.ex | 3 ++- lib/cloak_ecto/types/date_time.ex | 3 ++- lib/cloak_ecto/types/decimal.ex | 3 ++- lib/cloak_ecto/types/float.ex | 3 ++- lib/cloak_ecto/types/integer.ex | 3 ++- lib/cloak_ecto/types/integer_list.ex | 3 ++- lib/cloak_ecto/types/map.ex | 3 ++- lib/cloak_ecto/types/naive_date_time.ex | 3 ++- lib/cloak_ecto/types/string_list.ex | 3 ++- lib/cloak_ecto/types/time.ex | 3 ++- 12 files changed, 31 insertions(+), 12 deletions(-) diff --git a/lib/cloak_ecto/type.ex b/lib/cloak_ecto/type.ex index 739c5bc..f19767c 100644 --- a/lib/cloak_ecto/type.ex +++ b/lib/cloak_ecto/type.ex @@ -4,7 +4,7 @@ defmodule Cloak.Ecto.Type do @callback __cloak__ :: Keyword.t() defmacro __using__(opts) do - vault = Keyword.fetch!(opts, :vault) + vault = Cloak.Ecto.Type.__get_vault__(opts) label = opts[:label] closure = !!opts[:closure] @@ -120,4 +120,12 @@ defmodule Cloak.Ecto.Type do end end end + + @default_vault Application.compile_env(:cloak, :default_vault) + + @doc false + def __get_vault__(opts) do + Keyword.get(opts, :vault) || @default_vault || + raise ArgumentError, "No `:vault` option was provided, and no default vault was configured" + end end diff --git a/lib/cloak_ecto/types/binary.ex b/lib/cloak_ecto/types/binary.ex index 077a90b..52fd620 100644 --- a/lib/cloak_ecto/types/binary.ex +++ b/lib/cloak_ecto/types/binary.ex @@ -25,7 +25,8 @@ defmodule Cloak.Ecto.Binary do @doc false defmacro __using__(opts) do - opts = Keyword.merge(opts, vault: Keyword.fetch!(opts, :vault)) + vault = Cloak.Ecto.Type.__get_vault__(opts) + opts = Keyword.merge(opts, vault: vault) quote location: :keep do use Cloak.Ecto.Type, unquote(opts) diff --git a/lib/cloak_ecto/types/date.ex b/lib/cloak_ecto/types/date.ex index b3aeb86..1123dea 100644 --- a/lib/cloak_ecto/types/date.ex +++ b/lib/cloak_ecto/types/date.ex @@ -24,7 +24,8 @@ defmodule Cloak.Ecto.Date do """ defmacro __using__(opts) do - opts = Keyword.merge(opts, vault: Keyword.fetch!(opts, :vault)) + vault = Cloak.Ecto.Type.__get_vault__(opts) + opts = Keyword.merge(opts, vault: vault) quote do use Cloak.Ecto.Type, unquote(opts) diff --git a/lib/cloak_ecto/types/date_time.ex b/lib/cloak_ecto/types/date_time.ex index 1483647..40ebf43 100644 --- a/lib/cloak_ecto/types/date_time.ex +++ b/lib/cloak_ecto/types/date_time.ex @@ -24,7 +24,8 @@ defmodule Cloak.Ecto.DateTime do """ defmacro __using__(opts) do - opts = Keyword.merge(opts, vault: Keyword.fetch!(opts, :vault)) + vault = Cloak.Ecto.Type.__get_vault__(opts) + opts = Keyword.merge(opts, vault: vault) quote do use Cloak.Ecto.Type, unquote(opts) diff --git a/lib/cloak_ecto/types/decimal.ex b/lib/cloak_ecto/types/decimal.ex index 0d68c8d..a66b955 100644 --- a/lib/cloak_ecto/types/decimal.ex +++ b/lib/cloak_ecto/types/decimal.ex @@ -28,7 +28,8 @@ defmodule Cloak.Ecto.Decimal do @doc false defmacro __using__(opts) do - opts = Keyword.merge(opts, vault: Keyword.fetch!(opts, :vault)) + vault = Cloak.Ecto.Type.__get_vault__(opts) + opts = Keyword.merge(opts, vault: vault) quote do use Cloak.Ecto.Type, unquote(opts) diff --git a/lib/cloak_ecto/types/float.ex b/lib/cloak_ecto/types/float.ex index 8192ca5..c2c9334 100644 --- a/lib/cloak_ecto/types/float.ex +++ b/lib/cloak_ecto/types/float.ex @@ -25,7 +25,8 @@ defmodule Cloak.Ecto.Float do """ @doc false defmacro __using__(opts) do - opts = Keyword.merge(opts, vault: Keyword.fetch!(opts, :vault)) + vault = Cloak.Ecto.Type.__get_vault__(opts) + opts = Keyword.merge(opts, vault: vault) quote do use Cloak.Ecto.Type, unquote(opts) diff --git a/lib/cloak_ecto/types/integer.ex b/lib/cloak_ecto/types/integer.ex index a88966c..9a21511 100644 --- a/lib/cloak_ecto/types/integer.ex +++ b/lib/cloak_ecto/types/integer.ex @@ -25,7 +25,8 @@ defmodule Cloak.Ecto.Integer do @doc false defmacro __using__(opts) do - opts = Keyword.merge(opts, vault: Keyword.fetch!(opts, :vault)) + vault = Cloak.Ecto.Type.__get_vault__(opts) + opts = Keyword.merge(opts, vault: vault) quote do use Cloak.Ecto.Type, unquote(opts) diff --git a/lib/cloak_ecto/types/integer_list.ex b/lib/cloak_ecto/types/integer_list.ex index 7487184..6971b03 100644 --- a/lib/cloak_ecto/types/integer_list.ex +++ b/lib/cloak_ecto/types/integer_list.ex @@ -32,7 +32,8 @@ defmodule Cloak.Ecto.IntegerList do @doc false defmacro __using__(opts) do - opts = Keyword.merge(opts, vault: Keyword.fetch!(opts, :vault)) + vault = Cloak.Ecto.Type.__get_vault__(opts) + opts = Keyword.merge(opts, vault: vault) quote location: :keep do use Cloak.Ecto.Type, unquote(opts) diff --git a/lib/cloak_ecto/types/map.ex b/lib/cloak_ecto/types/map.ex index 00534d9..f40266e 100644 --- a/lib/cloak_ecto/types/map.ex +++ b/lib/cloak_ecto/types/map.ex @@ -45,7 +45,8 @@ defmodule Cloak.Ecto.Map do """ defmacro __using__(opts) do - opts = Keyword.merge(opts, vault: Keyword.fetch!(opts, :vault)) + vault = Cloak.Ecto.Type.__get_vault__(opts) + opts = Keyword.merge(opts, vault: vault) quote location: :keep do use Cloak.Ecto.Type, unquote(opts) diff --git a/lib/cloak_ecto/types/naive_date_time.ex b/lib/cloak_ecto/types/naive_date_time.ex index b52f8b1..0eb004b 100644 --- a/lib/cloak_ecto/types/naive_date_time.ex +++ b/lib/cloak_ecto/types/naive_date_time.ex @@ -25,7 +25,8 @@ defmodule Cloak.Ecto.NaiveDateTime do @doc false defmacro __using__(opts) do - opts = Keyword.merge(opts, vault: Keyword.fetch!(opts, :vault)) + vault = Cloak.Ecto.Type.__get_vault__(opts) + opts = Keyword.merge(opts, vault: vault) quote location: :keep do use Cloak.Ecto.Type, unquote(opts) diff --git a/lib/cloak_ecto/types/string_list.ex b/lib/cloak_ecto/types/string_list.ex index 9feef3b..953a3c2 100644 --- a/lib/cloak_ecto/types/string_list.ex +++ b/lib/cloak_ecto/types/string_list.ex @@ -36,7 +36,8 @@ defmodule Cloak.Ecto.StringList do @doc false defmacro __using__(opts) do - opts = Keyword.merge(opts, vault: Keyword.fetch!(opts, :vault)) + vault = Cloak.Ecto.Type.__get_vault__(opts) + opts = Keyword.merge(opts, vault: vault) quote location: :keep do use Cloak.Ecto.Type, unquote(opts) diff --git a/lib/cloak_ecto/types/time.ex b/lib/cloak_ecto/types/time.ex index 59f7fce..d07192c 100644 --- a/lib/cloak_ecto/types/time.ex +++ b/lib/cloak_ecto/types/time.ex @@ -25,7 +25,8 @@ defmodule Cloak.Ecto.Time do @doc false defmacro __using__(opts) do - opts = Keyword.merge(opts, vault: Keyword.fetch!(opts, :vault)) + vault = Cloak.Ecto.Type.__get_vault__(opts) + opts = Keyword.merge(opts, vault: vault) quote location: :keep do use Cloak.Ecto.Type, unquote(opts)