From 8cfe0ee6ccba51349bda0a7619b1643ddef9cdf4 Mon Sep 17 00:00:00 2001 From: Marcel Otto Date: Fri, 19 Nov 2021 21:10:47 +0100 Subject: [PATCH] Drop support for Elixir versions < 1.10 --- .github/workflows/ci.yml | 3 -- CHANGELOG.md | 2 + lib/rdf/dataset.ex | 70 +++++++++------------------------- lib/rdf/description.ex | 52 ++++++------------------- lib/rdf/graph.ex | 50 ++++++------------------ mix.exs | 2 +- test/support/rdf_case.ex | 9 ----- test/unit/dataset_test.exs | 10 ++--- test/unit/description_test.exs | 24 ++++++------ test/unit/graph_test.exs | 20 +++++----- 10 files changed, 71 insertions(+), 171 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f9b23a..3bb03b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cf783a..a554847 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/rdf/dataset.ex b/lib/rdf/dataset.ex index eb8431f..6ec6b70 100644 --- a/lib/rdf/dataset.ex +++ b/lib/rdf/dataset.ex @@ -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 diff --git a/lib/rdf/description.ex b/lib/rdf/description.ex index 0d5efcf..e966113 100644 --- a/lib/rdf/description.ex +++ b/lib/rdf/description.ex @@ -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 diff --git a/lib/rdf/graph.ex b/lib/rdf/graph.ex index 0de34e8..8bdb6a2 100644 --- a/lib/rdf/graph.ex +++ b/lib/rdf/graph.ex @@ -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 diff --git a/mix.exs b/mix.exs index 3b48628..7952ad1 100644 --- a/mix.exs +++ b/mix.exs @@ -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(), diff --git a/test/support/rdf_case.ex b/test/support/rdf_case.ex index be383d2..6ea361e 100644 --- a/test/support/rdf_case.ex +++ b/test/support/rdf_case.ex @@ -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) diff --git a/test/unit/dataset_test.exs b/test/unit/dataset_test.exs index 48bdfe8..88e23ad 100644 --- a/test/unit/dataset_test.exs +++ b/test/unit/dataset_test.exs @@ -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 diff --git a/test/unit/description_test.exs b/test/unit/description_test.exs index 2540cbe..08e02ab 100644 --- a/test/unit/description_test.exs +++ b/test/unit/description_test.exs @@ -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 diff --git a/test/unit/graph_test.exs b/test/unit/graph_test.exs index 0e84c1c..9467f6d 100644 --- a/test/unit/graph_test.exs +++ b/test/unit/graph_test.exs @@ -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