Skip to content

Commit

Permalink
Merge pull request #47 from lanodan/fix/elixir-1.14
Browse files Browse the repository at this point in the history
Prometheus.Erlang: Fix Kernel.Utils.defdelegate usage for Elixir 1.14
  • Loading branch information
deadtrickster authored Nov 16, 2023
2 parents d09a312 + 31f7fbe commit 4c165f0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/prometheus/erlang.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ defmodule Prometheus.Erlang do
end
end

if Version.match?(System.version(), "< 1.14.0-rc.0") do
def defdelegate_each(fun, opts), do: Kernel.Utils.defdelegate(fun, opts)
else
def defdelegate_each(fun, opts), do: Kernel.Utils.defdelegate_each(fun, opts)
end

defmacro delegate(fun, opts \\ []) do
fun = Macro.escape(fun, unquote: true)

quote bind_quoted: [fun: fun, opts: opts] do
target = Keyword.get(opts, :to, @erlang_module)

{name, args, as, as_args} = Kernel.Utils.defdelegate(fun, opts)
{name, args, as, as_args} = defdelegate_each(fun, opts)

def unquote(name)(unquote_splicing(args)) do
Prometheus.Error.with_prometheus_error(
Expand All @@ -36,7 +42,7 @@ defmodule Prometheus.Erlang do
quote bind_quoted: [fun: fun, opts: opts] do
target = Keyword.get(opts, :to, @erlang_module)

{name, args, as, [spec | as_args]} = Kernel.Utils.defdelegate(fun, opts)
{name, args, as, [spec | as_args]} = defdelegate_each(fun, opts)

def unquote(name)(unquote_splicing(args)) do
{registry, name, labels} = Metric.parse_spec(unquote(spec))
Expand Down

0 comments on commit 4c165f0

Please sign in to comment.