core: RDF.Serialization.Encoder behaviour

This commit is contained in:
Marcel Otto 2017-05-19 18:10:32 +02:00
parent e9820ab554
commit cd7e91ec9d

View file

@ -0,0 +1,23 @@
defmodule RDF.Serialization.Encoder do
@moduledoc false
@callback encode(RDF.Dataset, keyword) :: keyword(String.t)
@callback encode!(RDF.Dataset, keyword) :: String.t
defmacro __using__(_) do
quote bind_quoted: [], unquote: true do
@behaviour unquote(__MODULE__)
def encode!(data, opts \\ []) do
case encode(data, opts) do
{:ok, data} -> data
{:error, reason} -> raise reason
end
end
defoverridable [encode!: 2]
end
end
end