core: RDF.Serialization.Encoder behaviour
This commit is contained in:
parent
e9820ab554
commit
cd7e91ec9d
1 changed files with 23 additions and 0 deletions
23
lib/rdf/serialization/encoder.ex
Normal file
23
lib/rdf/serialization/encoder.ex
Normal 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
|
Loading…
Reference in a new issue