From f76687530b62b241debf59207840de553c8259ea Mon Sep 17 00:00:00 2001 From: Marcel Otto Date: Thu, 7 Apr 2022 01:08:17 +0200 Subject: [PATCH] Add exclude/1 function for Graph builder blocks --- .formatter.exs | 3 ++- lib/rdf/graph_builder.ex | 2 ++ test/unit/graph_builder_test.exs | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.formatter.exs b/.formatter.exs index 2743f09..e1a8412 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -3,7 +3,8 @@ locals_without_parens = [ def_facet_constraint: 2, def_applicable_facet: 1, bgp: 1, - build: 2 + build: 2, + exclude: 1 ] [ diff --git a/lib/rdf/graph_builder.ex b/lib/rdf/graph_builder.ex index fc3bd21..1c78b1b 100644 --- a/lib/rdf/graph_builder.ex +++ b/lib/rdf/graph_builder.ex @@ -12,6 +12,8 @@ defmodule RDF.Graph.Builder do defdelegate a(s, o1, o2, o3), to: RDF.NS.RDF, as: :type defdelegate a(s, o1, o2, o3, o4), to: RDF.NS.RDF, as: :type defdelegate a(s, o1, o2, o3, o4, o5), to: RDF.NS.RDF, as: :type + + def exclude(_), do: nil end def build({:__block__, _, block}, opts) do diff --git a/test/unit/graph_builder_test.exs b/test/unit/graph_builder_test.exs index c299580..111b78e 100644 --- a/test/unit/graph_builder_test.exs +++ b/test/unit/graph_builder_test.exs @@ -490,6 +490,19 @@ defmodule RDF.Graph.BuilderTest do end end + test "exclude" do + graph = + RDF.Graph.build do + exclude "this is not a triple" + + EX.S |> EX.p(EX.O) + + exclude "this is not a triple" + end + + assert graph == RDF.graph(EX.S |> EX.p(EX.O)) + end + test "opts" do initial = {EX.S, EX.p(), "init"}