From a874f0c20f38eba56cc2c0dff340e2a029a0904d Mon Sep 17 00:00:00 2001 From: Greg Rychlewski Date: Fri, 28 Jun 2024 07:29:48 -0400 Subject: [PATCH] allow custom extensions to use options --- lib/postgrex/type_module.ex | 13 ++++++------- lib/postgrex/utils.ex | 6 +++--- test/custom_extensions_test.exs | 9 +++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/postgrex/type_module.ex b/lib/postgrex/type_module.ex index cb6f4d57..61703f5f 100644 --- a/lib/postgrex/type_module.ex +++ b/lib/postgrex/type_module.ex @@ -920,9 +920,12 @@ defmodule Postgrex.TypeModule do end end - defp configure(extensions, opts) do - defaults = Postgrex.Utils.default_extensions(opts) - Enum.map(extensions ++ defaults, &configure/1) + defp configure(customs, opts) do + defaults = Postgrex.Utils.default_extensions() + + Enum.map(customs ++ defaults, fn extension -> + configure({extension, opts}) + end) end defp configure({extension, opts}) do @@ -932,10 +935,6 @@ defmodule Postgrex.TypeModule do {extension, {state, matching, format}} end - defp configure(extension) do - configure({extension, []}) - end - defp define_inline(module, config, opts) do quoted = [ directives(config, opts), diff --git a/lib/postgrex/utils.ex b/lib/postgrex/utils.ex index e227c346..6877f31a 100644 --- a/lib/postgrex/utils.ex +++ b/lib/postgrex/utils.ex @@ -57,9 +57,9 @@ defmodule Postgrex.Utils do @doc """ List all default extensions. """ - @spec default_extensions(Keyword.t()) :: [{module(), Keyword.t()}] - def default_extensions(opts \\ []) do - Enum.map(@extensions, &{&1, opts}) + @spec default_extensions() :: [module()] + def default_extensions() do + @extensions end @doc """ diff --git a/test/custom_extensions_test.exs b/test/custom_extensions_test.exs index b66f8cb9..5ee34801 100644 --- a/test/custom_extensions_test.exs +++ b/test/custom_extensions_test.exs @@ -10,8 +10,9 @@ defmodule CustomExtensionsTest do defmodule BinaryExtension do @behaviour Postgrex.Extension - def init([]), - do: [] + def init(_opts) do + [] + end def matching([]), do: [send: "int4send"] @@ -36,7 +37,7 @@ defmodule CustomExtensionsTest do defmodule TextExtension do @behaviour Postgrex.Extension - def init([]), + def init(_opts), do: {} def matching({}), @@ -63,7 +64,7 @@ defmodule CustomExtensionsTest do defmodule BadExtension do @behaviour Postgrex.Extension - def init([]), + def init(_opts), do: [] def matching([]),