Skip to content

Commit

Permalink
Replace use of Keyword.pop!/2 (only available in Elixir >= v1.10)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotto committed Sep 21, 2020
1 parent de6ade8 commit 5df8c95
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/sparql_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ defmodule SPARQL.Client do
See documentation of the generic `update/3` function and the [module documentation](`SPARQL.Client`) for the available options.
"""
def load(endpoint, opts) when is_list(opts) do
{from, opts} = Keyword.pop!(opts, :from)
{from, opts} = pop_required_keyword(opts, :from)
{to, opts} = Keyword.pop(opts, :to)
{silent, opts} = Keyword.pop(opts, :silent)

Expand Down Expand Up @@ -501,7 +501,7 @@ defmodule SPARQL.Client do
See documentation of the generic `update/3` function and the [module documentation](`SPARQL.Client`) for the available options.
"""
def unquote(form)(endpoint, opts) when is_list(opts) do
{graph, opts} = Keyword.pop!(opts, :graph)
{graph, opts} = pop_required_keyword(opts, :graph)
{silent, opts} = Keyword.pop(opts, :silent)

with {:ok, update_string} <- apply(Client.Update.Builder, unquote(form), [graph, silent]) do
Expand Down Expand Up @@ -557,8 +557,8 @@ defmodule SPARQL.Client do
See documentation of the generic `update/3` function and the [module documentation](`SPARQL.Client`) for the available options.
"""
def unquote(form)(endpoint, opts) when is_list(opts) do
{from, opts} = Keyword.pop!(opts, :from)
{to, opts} = Keyword.pop!(opts, :to)
{from, opts} = pop_required_keyword(opts, :from)
{to, opts} = pop_required_keyword(opts, :to)
{silent, opts} = Keyword.pop(opts, :silent)

with {:ok, update_string} <- apply(Client.Update.Builder, unquote(form), [from, to, silent]) do
Expand Down Expand Up @@ -627,4 +627,11 @@ defmodule SPARQL.Client do
defp raw_mode?(opts) do
Keyword.get(opts, :raw_mode, default_raw_mode())
end

defp pop_required_keyword(opts, key) do
case Keyword.pop(opts, key) do
{nil, _} -> raise "missing required keyword option #{inspect(key)}"
result -> result
end
end
end

0 comments on commit 5df8c95

Please sign in to comment.