Drop support for Elixir versions < 1.10

This commit is contained in:
Marcel Otto 2021-11-19 21:10:47 +01:00
parent 2abb17ff6a
commit 8cfe0ee6cc
10 changed files with 71 additions and 171 deletions

View file

@ -15,9 +15,6 @@ jobs:
fail-fast: false
matrix:
include:
- pair:
elixir: 1.9.4
otp: 21.3
- pair:
elixir: 1.10.4
otp: 21.3

View file

@ -7,6 +7,8 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
## Unreleased
Elixir versions < 1.10 are no longer supported
### Added
- RDF-star support on the RDF data structures and the N-Triples, N-Quads, Turtle

View file

@ -156,17 +156,9 @@ defmodule RDF.Dataset do
|> Enum.reduce(dataset, &add(&2, &1, opts))
end
if Version.match?(System.version(), "~> 1.10") do
def add(dataset, input, opts)
when is_list(input) or (is_map(input) and not is_struct(input)) do
Enum.reduce(input, dataset, &add(&2, &1, opts))
end
else
def add(_, %_{}, _), do: raise(ArgumentError, "structs are not allowed as input")
def add(dataset, input, opts) when is_list(input) or is_map(input) do
Enum.reduce(input, dataset, &add(&2, &1, opts))
end
def add(dataset, input, opts)
when is_list(input) or (is_map(input) and not is_struct(input)) do
Enum.reduce(input, dataset, &add(&2, &1, opts))
end
def add(%__MODULE__{} = dataset, input, opts),
@ -312,25 +304,14 @@ defmodule RDF.Dataset do
|> Enum.reduce(dataset, &delete(&2, &1, opts))
end
if Version.match?(System.version(), "~> 1.10") do
def delete(dataset, input, opts)
when is_list(input) or (is_map(input) and not is_struct(input)) do
Enum.reduce(input, dataset, &delete(&2, &1, opts))
end
def delete(%__MODULE__{} = dataset, input, opts) when not is_struct(input),
do: do_delete(dataset, destination_graph(opts), input, opts)
else
def delete(_, %_{}, _), do: raise(ArgumentError, "structs are not allowed as input")
def delete(dataset, input, opts) when is_list(input) or is_map(input) do
Enum.reduce(input, dataset, &delete(&2, &1, opts))
end
def delete(%__MODULE__{} = dataset, input, opts),
do: do_delete(dataset, destination_graph(opts), input, opts)
def delete(dataset, input, opts)
when is_list(input) or (is_map(input) and not is_struct(input)) do
Enum.reduce(input, dataset, &delete(&2, &1, opts))
end
def delete(%__MODULE__{} = dataset, input, opts) when not is_struct(input),
do: do_delete(dataset, destination_graph(opts), input, opts)
defp do_delete(dataset, graph_name, input, opts) do
if existing_graph = dataset.graphs[graph_name] do
new_graph = Graph.delete(existing_graph, input, opts)
@ -709,25 +690,14 @@ defmodule RDF.Dataset do
|> Enum.all?(&include?(dataset, &1, opts))
end
if Version.match?(System.version(), "~> 1.10") do
def include?(dataset, input, opts)
when is_list(input) or (is_map(input) and not is_struct(input)) do
Enum.all?(input, &include?(dataset, &1, opts))
end
def include?(dataset, input, opts) when not is_struct(input),
do: do_include?(dataset, destination_graph(opts), input, opts)
else
def include?(_, %_{}, _), do: raise(ArgumentError, "structs are not allowed as input")
def include?(dataset, input, opts) when is_list(input) or is_map(input) do
Enum.all?(input, &include?(dataset, &1, opts))
end
def include?(dataset, input, opts),
do: do_include?(dataset, destination_graph(opts), input, opts)
def include?(dataset, input, opts)
when is_list(input) or (is_map(input) and not is_struct(input)) do
Enum.all?(input, &include?(dataset, &1, opts))
end
def include?(dataset, input, opts) when not is_struct(input),
do: do_include?(dataset, destination_graph(opts), input, opts)
defp do_include?(%__MODULE__{} = dataset, graph_name, input, opts) do
if graph = dataset.graphs[graph_name] do
Graph.include?(graph, input, opts)
@ -904,13 +874,9 @@ defmodule RDF.Dataset do
def member?(dataset, statement), do: {:ok, Dataset.include?(dataset, statement)}
def count(dataset), do: {:ok, Dataset.statement_count(dataset)}
if Version.match?(System.version(), "~> 1.10") do
def slice(dataset) do
size = Dataset.statement_count(dataset)
{:ok, size, &Enumerable.List.slice(Dataset.statements(dataset), &1, &2, size)}
end
else
def slice(_), do: {:error, __MODULE__}
def slice(dataset) do
size = Dataset.statement_count(dataset)
{:ok, size, &Enumerable.List.slice(Dataset.statements(dataset), &1, &2, size)}
end
def reduce(dataset, acc, fun) do

View file

@ -165,17 +165,9 @@ defmodule RDF.Description do
}
end
if Version.match?(System.version(), "~> 1.10") do
def add(description, input, opts)
when is_list(input) or (is_map(input) and not is_struct(input)) do
Enum.reduce(input, description, &add(&2, &1, opts))
end
else
def add(_, %_{}, _), do: raise(ArgumentError, "structs are not allowed as input")
def add(description, input, opts) when is_list(input) or is_map(input) do
Enum.reduce(input, description, &add(&2, &1, opts))
end
def add(description, input, opts)
when is_list(input) or (is_map(input) and not is_struct(input)) do
Enum.reduce(input, description, &add(&2, &1, opts))
end
@doc """
@ -298,17 +290,9 @@ defmodule RDF.Description do
}
end
if Version.match?(System.version(), "~> 1.10") do
def delete(description, input, opts)
when is_list(input) or (is_map(input) and not is_struct(input)) do
Enum.reduce(input, description, &delete(&2, &1, opts))
end
else
def delete(_, %_{}, _), do: raise(ArgumentError, "structs are not allowed as input")
def delete(description, input, opts) when is_list(input) or is_map(input) do
Enum.reduce(input, description, &delete(&2, &1, opts))
end
def delete(description, input, opts)
when is_list(input) or (is_map(input) and not is_struct(input)) do
Enum.reduce(input, description, &delete(&2, &1, opts))
end
@doc """
@ -698,17 +682,9 @@ defmodule RDF.Description do
def include?(%__MODULE__{}, %__MODULE__{}, _), do: false
if Version.match?(System.version(), "~> 1.10") do
def include?(description, input, opts)
when is_list(input) or (is_map(input) and not is_struct(input)) do
Enum.all?(input, &include?(description, &1, opts))
end
else
def include?(_, %_{}, _), do: raise(ArgumentError, "structs are not allowed as input")
def include?(description, input, opts) when is_list(input) or is_map(input) do
Enum.all?(input, &include?(description, &1, opts))
end
def include?(description, input, opts)
when is_list(input) or (is_map(input) and not is_struct(input)) do
Enum.all?(input, &include?(description, &1, opts))
end
@doc """
@ -877,13 +853,9 @@ defmodule RDF.Description do
def count(desc), do: {:ok, Description.statement_count(desc)}
if Version.match?(System.version(), "~> 1.10") do
def slice(desc) do
size = Description.statement_count(desc)
{:ok, size, &Enumerable.List.slice(Description.triples(desc), &1, &2, size)}
end
else
def slice(_), do: {:error, __MODULE__}
def slice(desc) do
size = Description.statement_count(desc)
{:ok, size, &Enumerable.List.slice(Description.triples(desc), &1, &2, size)}
end
def reduce(desc, acc, fun) do

View file

@ -224,16 +224,8 @@ defmodule RDF.Graph do
end
end
if Version.match?(System.version(), "~> 1.10") do
def add(graph, input, opts) when is_list(input) or (is_map(input) and not is_struct(input)) do
Enum.reduce(input, graph, &add(&2, &1, opts))
end
else
def add(_, %_{}, _), do: raise(ArgumentError, "structs are not allowed as input")
def add(graph, input, opts) when is_list(input) or is_map(input) do
Enum.reduce(input, graph, &add(&2, &1, opts))
end
def add(graph, input, opts) when is_list(input) or (is_map(input) and not is_struct(input)) do
Enum.reduce(input, graph, &add(&2, &1, opts))
end
defp do_add(%__MODULE__{descriptions: descriptions} = graph, subject, statements, opts) do
@ -411,17 +403,9 @@ defmodule RDF.Graph do
end)
end
if Version.match?(System.version(), "~> 1.10") do
def delete(%__MODULE__{} = graph, input, opts)
when is_list(input) or (is_map(input) and not is_struct(input)) do
Enum.reduce(input, graph, &delete(&2, &1, opts))
end
else
def delete(_, %_{}, _), do: raise(ArgumentError, "structs are not allowed as input")
def delete(%__MODULE__{} = graph, input, opts) when is_list(input) or is_map(input) do
Enum.reduce(input, graph, &delete(&2, &1, opts))
end
def delete(%__MODULE__{} = graph, input, opts)
when is_list(input) or (is_map(input) and not is_struct(input)) do
Enum.reduce(input, graph, &delete(&2, &1, opts))
end
defp do_delete(%__MODULE__{descriptions: descriptions} = graph, subject, input, opts) do
@ -953,17 +937,9 @@ defmodule RDF.Graph do
|> Enum.all?(&include?(graph, &1, opts))
end
if Version.match?(System.version(), "~> 1.10") do
def include?(graph, input, opts)
when is_list(input) or (is_map(input) and not is_struct(input)) do
Enum.all?(input, &include?(graph, &1, opts))
end
else
def include?(_, %_{}, _), do: raise(ArgumentError, "structs are not allowed as input")
def include?(graph, input, opts) when is_list(input) or is_map(input) do
Enum.all?(input, &include?(graph, &1, opts))
end
def include?(graph, input, opts)
when is_list(input) or (is_map(input) and not is_struct(input)) do
Enum.all?(input, &include?(graph, &1, opts))
end
defp do_include?(%__MODULE__{descriptions: descriptions}, subject, input, opts) do
@ -1265,13 +1241,9 @@ defmodule RDF.Graph do
def member?(graph, triple), do: {:ok, Graph.include?(graph, triple)}
def count(graph), do: {:ok, Graph.statement_count(graph)}
if Version.match?(System.version(), "~> 1.10") do
def slice(graph) do
size = Graph.statement_count(graph)
{:ok, size, &Enumerable.List.slice(Graph.triples(graph), &1, &2, size)}
end
else
def slice(_), do: {:error, __MODULE__}
def slice(graph) do
size = Graph.statement_count(graph)
{:ok, size, &Enumerable.List.slice(Graph.triples(graph), &1, &2, size)}
end
def reduce(graph, acc, fun) do

View file

@ -9,7 +9,7 @@ defmodule RDF.Mixfile do
[
app: :rdf,
version: @version,
elixir: "~> 1.9",
elixir: "~> 1.10",
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
deps: deps(),

View file

@ -26,15 +26,6 @@ defmodule RDF.Test.Case do
end
end
# TODO: Remove this when we dropped support for Elixir versions < 1.10
def struct_not_allowed_as_input_error do
if Version.match?(System.version(), "~> 1.10") do
FunctionClauseError
else
ArgumentError
end
end
def string_to_stream(string) do
{:ok, pid} = StringIO.open(string)
IO.binstream(pid, :line)

View file

@ -879,7 +879,7 @@ defmodule RDF.DatasetTest do
end
test "structs are causing an error" do
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Dataset.add(dataset(), Date.utc_today())
end
end
@ -1178,7 +1178,7 @@ defmodule RDF.DatasetTest do
end
test "structs are causing an error" do
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Dataset.put(dataset(), Date.utc_today())
end
end
@ -1365,7 +1365,7 @@ defmodule RDF.DatasetTest do
end
test "structs are causing an error" do
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Dataset.put_properties(dataset(), Date.utc_today())
end
end
@ -1546,7 +1546,7 @@ defmodule RDF.DatasetTest do
end
test "structs are causing an error" do
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Dataset.delete(dataset(), Date.utc_today())
end
end
@ -1659,7 +1659,7 @@ defmodule RDF.DatasetTest do
end
test "structs are causing an error" do
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Dataset.include?(dataset(), Date.utc_today())
end
end

View file

@ -361,15 +361,15 @@ defmodule RDF.DescriptionTest do
end
test "structs are causing an error" do
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Description.add(description(), Date.utc_today())
end
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Description.add(description(), RDF.graph())
end
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Description.add(description(), RDF.dataset())
end
end
@ -518,15 +518,15 @@ defmodule RDF.DescriptionTest do
end
test "structs are causing an error" do
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Description.put(description(), Date.utc_today())
end
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Description.put(description(), RDF.graph())
end
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Description.put(description(), RDF.dataset())
end
end
@ -666,15 +666,15 @@ defmodule RDF.DescriptionTest do
end
test "structs are causing an error" do
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Description.delete(description(), Date.utc_today())
end
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Description.delete(description(), RDF.graph())
end
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Description.delete(description(), RDF.dataset())
end
end
@ -821,15 +821,15 @@ defmodule RDF.DescriptionTest do
end
test "structs are causing an error" do
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Description.include?(description(), Date.utc_today())
end
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Description.include?(description(), RDF.graph())
end
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Description.include?(description(), RDF.dataset())
end
end

View file

@ -538,11 +538,11 @@ defmodule RDF.GraphTest do
end
test "structs are causing an error" do
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Graph.add(graph(), Date.utc_today())
end
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Graph.add(graph(), RDF.dataset())
end
end
@ -736,11 +736,11 @@ defmodule RDF.GraphTest do
end
test "structs are causing an error" do
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Graph.put(graph(), Date.utc_today())
end
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Graph.put(graph(), RDF.dataset())
end
end
@ -944,11 +944,11 @@ defmodule RDF.GraphTest do
end
test "structs are causing an error" do
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Graph.put_properties(graph(), Date.utc_today())
end
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Graph.put_properties(graph(), RDF.dataset())
end
end
@ -1076,11 +1076,11 @@ defmodule RDF.GraphTest do
end
test "structs are causing an error" do
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Graph.delete(graph(), Date.utc_today())
end
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Graph.delete(graph(), RDF.dataset())
end
end
@ -1243,11 +1243,11 @@ defmodule RDF.GraphTest do
end
test "structs are causing an error" do
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Graph.include?(graph(), Date.utc_today())
end
assert_raise struct_not_allowed_as_input_error(), fn ->
assert_raise FunctionClauseError, fn ->
Graph.include?(graph(), RDF.dataset())
end
end