Fix dialyzer warning
This commit is contained in:
parent
8d98461e0b
commit
e3454f73ce
5 changed files with 27 additions and 15 deletions
|
@ -4,7 +4,7 @@ defmodule RDF.Serialization.Encoder do
|
||||||
`RDF.Serialization` format.
|
`RDF.Serialization` format.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias RDF.{Dataset, Graph}
|
alias RDF.{Dataset, Graph, Description}
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Encodes a `RDF.Graph` or `RDF.Dataset`.
|
Encodes a `RDF.Graph` or `RDF.Dataset`.
|
||||||
|
@ -12,7 +12,8 @@ defmodule RDF.Serialization.Encoder do
|
||||||
It returns an `{:ok, string}` tuple, with `string` being the serialized
|
It returns an `{:ok, string}` tuple, with `string` being the serialized
|
||||||
`RDF.Graph` or `RDF.Dataset`, or `{:error, reason}` if an error occurs.
|
`RDF.Graph` or `RDF.Dataset`, or `{:error, reason}` if an error occurs.
|
||||||
"""
|
"""
|
||||||
@callback encode(Graph.t() | Dataset.t(), keyword | map) :: {:ok, String.t()} | {:error, any}
|
@callback encode(Description.t() | Graph.t() | Dataset.t(), keyword | map) ::
|
||||||
|
{:ok, String.t()} | {:error, any}
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Encodes a `RDF.Graph` or `RDF.Dataset`.
|
Encodes a `RDF.Graph` or `RDF.Dataset`.
|
||||||
|
@ -22,7 +23,7 @@ defmodule RDF.Serialization.Encoder do
|
||||||
Note: The `__using__` macro automatically provides an overridable default
|
Note: The `__using__` macro automatically provides an overridable default
|
||||||
implementation based on the non-bang `encode` function.
|
implementation based on the non-bang `encode` function.
|
||||||
"""
|
"""
|
||||||
@callback encode!(Graph.t() | Dataset.t(), keyword | map) :: String.t()
|
@callback encode!(Description.t() | Graph.t() | Dataset.t(), keyword | map) :: String.t()
|
||||||
|
|
||||||
defmacro __using__(_) do
|
defmacro __using__(_) do
|
||||||
quote bind_quoted: [], unquote: true do
|
quote bind_quoted: [], unquote: true do
|
||||||
|
@ -30,7 +31,7 @@ defmodule RDF.Serialization.Encoder do
|
||||||
|
|
||||||
@impl unquote(__MODULE__)
|
@impl unquote(__MODULE__)
|
||||||
@dialyzer {:nowarn_function, encode!: 2}
|
@dialyzer {:nowarn_function, encode!: 2}
|
||||||
@spec encode!(Graph.t() | Dataset.t(), keyword) :: String.t()
|
@spec encode!(Description.t() | Graph.t() | Dataset.t(), keyword) :: String.t()
|
||||||
def encode!(data, opts \\ []) do
|
def encode!(data, opts \\ []) do
|
||||||
case encode(data, opts) do
|
case encode(data, opts) do
|
||||||
{:ok, data} -> data
|
{:ok, data} -> data
|
||||||
|
|
|
@ -28,7 +28,7 @@ defmodule RDF.Serialization.Format do
|
||||||
`decoder/0` functions in your `RDF.Serialization.Format` module.
|
`decoder/0` functions in your `RDF.Serialization.Format` module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias RDF.{Dataset, Graph}
|
alias RDF.{Dataset, Graph, Description}
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
An IRI of the serialization format.
|
An IRI of the serialization format.
|
||||||
|
@ -99,19 +99,21 @@ defmodule RDF.Serialization.Format do
|
||||||
def read_file!(file, opts \\ []),
|
def read_file!(file, opts \\ []),
|
||||||
do: RDF.Serialization.Reader.read_file!(decoder(), file, opts)
|
do: RDF.Serialization.Reader.read_file!(decoder(), file, opts)
|
||||||
|
|
||||||
@spec write_string(Graph.t() | Dataset.t(), keyword) :: {:ok, String.t()} | {:error, any}
|
@spec write_string(Description.t() | Graph.t() | Dataset.t(), keyword) ::
|
||||||
|
{:ok, String.t()} | {:error, any}
|
||||||
def write_string(data, opts \\ []),
|
def write_string(data, opts \\ []),
|
||||||
do: RDF.Serialization.Writer.write_string(encoder(), data, opts)
|
do: RDF.Serialization.Writer.write_string(encoder(), data, opts)
|
||||||
|
|
||||||
@spec write_string!(Graph.t() | Dataset.t(), keyword) :: String.t()
|
@spec write_string!(Description.t() | Graph.t() | Dataset.t(), keyword) :: String.t()
|
||||||
def write_string!(data, opts \\ []),
|
def write_string!(data, opts \\ []),
|
||||||
do: RDF.Serialization.Writer.write_string!(encoder(), data, opts)
|
do: RDF.Serialization.Writer.write_string!(encoder(), data, opts)
|
||||||
|
|
||||||
@spec write_file(Graph.t() | Dataset.t(), Path.t(), keyword) :: :ok | {:error, any}
|
@spec write_file(Description.t() | Graph.t() | Dataset.t(), Path.t(), keyword) ::
|
||||||
|
:ok | {:error, any}
|
||||||
def write_file(data, path, opts \\ []),
|
def write_file(data, path, opts \\ []),
|
||||||
do: RDF.Serialization.Writer.write_file(encoder(), data, path, opts)
|
do: RDF.Serialization.Writer.write_file(encoder(), data, path, opts)
|
||||||
|
|
||||||
@spec write_file!(Graph.t() | Dataset.t(), Path.t(), keyword) :: :ok
|
@spec write_file!(Description.t() | Graph.t() | Dataset.t(), Path.t(), keyword) :: :ok
|
||||||
def write_file!(data, path, opts \\ []),
|
def write_file!(data, path, opts \\ []),
|
||||||
do: RDF.Serialization.Writer.write_file!(encoder(), data, path, opts)
|
do: RDF.Serialization.Writer.write_file!(encoder(), data, path, opts)
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ defmodule RDF.Serialization.Writer do
|
||||||
use the proper `RDF.Serialization.Encoder` module.
|
use the proper `RDF.Serialization.Encoder` module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias RDF.{Dataset, Graph}
|
alias RDF.{Dataset, Graph, Description}
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Encodes and writes a graph or dataset to a string.
|
Encodes and writes a graph or dataset to a string.
|
||||||
|
@ -15,7 +15,7 @@ defmodule RDF.Serialization.Writer do
|
||||||
It returns an `{:ok, string}` tuple, with `string` being the serialized graph or
|
It returns an `{:ok, string}` tuple, with `string` being the serialized graph or
|
||||||
dataset, or `{:error, reason}` if an error occurs.
|
dataset, or `{:error, reason}` if an error occurs.
|
||||||
"""
|
"""
|
||||||
@spec write_string(module, Graph.t() | Dataset.t(), keyword) ::
|
@spec write_string(module, Description.t() | Graph.t() | Dataset.t(), keyword) ::
|
||||||
{:ok, String.t()} | {:error, any}
|
{:ok, String.t()} | {:error, any}
|
||||||
def write_string(encoder, data, opts \\ []) do
|
def write_string(encoder, data, opts \\ []) do
|
||||||
encoder.encode(data, opts)
|
encoder.encode(data, opts)
|
||||||
|
@ -26,7 +26,7 @@ defmodule RDF.Serialization.Writer do
|
||||||
|
|
||||||
As opposed to `write_string`, it raises an exception if an error occurs.
|
As opposed to `write_string`, it raises an exception if an error occurs.
|
||||||
"""
|
"""
|
||||||
@spec write_string!(module, Graph.t() | Dataset.t(), keyword) :: String.t()
|
@spec write_string!(module, Description.t() | Graph.t() | Dataset.t(), keyword) :: String.t()
|
||||||
def write_string!(encoder, data, opts \\ []) do
|
def write_string!(encoder, data, opts \\ []) do
|
||||||
encoder.encode!(data, opts)
|
encoder.encode!(data, opts)
|
||||||
end
|
end
|
||||||
|
@ -43,7 +43,8 @@ defmodule RDF.Serialization.Writer do
|
||||||
|
|
||||||
It returns `:ok` if successful or `{:error, reason}` if an error occurs.
|
It returns `:ok` if successful or `{:error, reason}` if an error occurs.
|
||||||
"""
|
"""
|
||||||
@spec write_file(module, Graph.t() | Dataset.t(), Path.t(), keyword) :: :ok | {:error, any}
|
@spec write_file(module, Description.t() | Graph.t() | Dataset.t(), Path.t(), keyword) ::
|
||||||
|
:ok | {:error, any}
|
||||||
def write_file(encoder, data, path, opts \\ []) do
|
def write_file(encoder, data, path, opts \\ []) do
|
||||||
with {:ok, encoded_string} <- write_string(encoder, data, opts) do
|
with {:ok, encoded_string} <- write_string(encoder, data, opts) do
|
||||||
File.write(path, encoded_string, file_mode(encoder, opts))
|
File.write(path, encoded_string, file_mode(encoder, opts))
|
||||||
|
@ -57,7 +58,7 @@ defmodule RDF.Serialization.Writer do
|
||||||
|
|
||||||
As opposed to `write_file`, it raises an exception if an error occurs.
|
As opposed to `write_file`, it raises an exception if an error occurs.
|
||||||
"""
|
"""
|
||||||
@spec write_file!(module, Graph.t() | Dataset.t(), Path.t(), keyword) :: :ok
|
@spec write_file!(module, Description.t() | Graph.t() | Dataset.t(), Path.t(), keyword) :: :ok
|
||||||
def write_file!(encoder, data, path, opts \\ []) do
|
def write_file!(encoder, data, path, opts \\ []) do
|
||||||
with encoded_string = write_string!(encoder, data, opts) do
|
with encoded_string = write_string!(encoder, data, opts) do
|
||||||
File.write!(path, encoded_string, file_mode(encoder, opts))
|
File.write!(path, encoded_string, file_mode(encoder, opts))
|
||||||
|
|
|
@ -36,7 +36,8 @@ defmodule RDF.Turtle.Encoder do
|
||||||
@ordered_properties MapSet.new(@predicate_order)
|
@ordered_properties MapSet.new(@predicate_order)
|
||||||
|
|
||||||
@impl RDF.Serialization.Encoder
|
@impl RDF.Serialization.Encoder
|
||||||
@spec encode(Graph.t() | Dataset.t(), keyword) :: {:ok, String.t()} | {:error, any}
|
@spec encode(Description.t() | Graph.t() | Dataset.t(), keyword) ::
|
||||||
|
{:ok, String.t()} | {:error, any}
|
||||||
def encode(data, opts \\ []) do
|
def encode(data, opts \\ []) do
|
||||||
base =
|
base =
|
||||||
Keyword.get(opts, :base, Keyword.get(opts, :base_iri))
|
Keyword.get(opts, :base, Keyword.get(opts, :base_iri))
|
||||||
|
|
|
@ -289,6 +289,13 @@ defmodule RDF.Turtle.EncoderTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "serializing a description" do
|
||||||
|
description = EX.S |> EX.p(EX.O)
|
||||||
|
|
||||||
|
assert Turtle.Encoder.encode!(description) ==
|
||||||
|
description |> Graph.new() |> Turtle.Encoder.encode!()
|
||||||
|
end
|
||||||
|
|
||||||
describe "serializing a dataset" do
|
describe "serializing a dataset" do
|
||||||
test "prefixes of the graphs are merged properly" do
|
test "prefixes of the graphs are merged properly" do
|
||||||
dataset =
|
dataset =
|
||||||
|
|
Loading…
Reference in a new issue