Rename RDF.Serialization.Format.content_type/0 to media_type/0

This commit is contained in:
Marcel Otto 2018-03-08 02:14:49 +01:00
parent 4f5b06c830
commit eb6ede55b9
6 changed files with 34 additions and 31 deletions

View file

@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
- rename `RDF.Serialization` behaviour to `RDF.Serialization.Format`; the new
`RDF.Serialization` module contains just simple RDF serialization related functions
- rename `RDF.Serialization.Format.content_type/0` to `RDF.Serialization.Format.media_type/0`
### Added
@ -20,7 +21,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
- `RDF.Serialization.formats/0`
- `RDF.Serialization.available_formats/0`
- `RDF.Serialization.format/1`
- `RDF.Serialization.format_by_content_type/1`
- `RDF.Serialization.format_by_media_type/1`
- `RDF.Serialization.format_by_extension/1`

View file

@ -5,25 +5,27 @@ defmodule RDF.Serialization.Format do
A `RDF.Serialization` for a format can be implemented like this
defmodule SomeFormat do
use RDF.Serialization
use RDF.Serialization.Format
import RDF.Sigils
@id ~I<http://example.com/some_format>
@extension "ext"
@content_type "application/some-format"
@id ~I<http://example.com/some_format>
@name :some_format
@extension "ext"
@media_type "application/some-format"
end
When `@id`, `@extension` and `@content_type` module attributes are defined the
resp. behaviour functions are generated automatically and return these values.
When `@id`, `@name`, `@extension` and `@media_type` module attributes are
defined the resp. behaviour functions are generated automatically and return
these values.
Then you'll have to do the main work by implementing a
`RDF.Serialization.Encoder` and a `RDF.Serialization.Decoder` for the format.
By default it is assumed that these are defined in `Encoder` and `Decoder`
moduler under the `RDF.Serialization` module of the format, i.e. in the example
above in `SomeFormat.Encoder` and `SomeFormat.Decoder`. If you want them in
another module, you'll have to override the `encoder/0` and/or `decoder/0`
functions in your `RDF.Serialization` module.
moduler under the `RDF.Serialization.Format` module of the format, i.e. in the
example above in `SomeFormat.Encoder` and `SomeFormat.Decoder`. If you want
them in another module, you'll have to override the `encoder/0` and/or
`decoder/0` functions in your `RDF.Serialization.Format` module.
"""
@doc """
@ -44,7 +46,7 @@ defmodule RDF.Serialization.Format do
@doc """
The MIME type of the serialization format.
"""
@callback content_type :: binary
@callback media_type :: binary
@doc """
A map with the supported options of the `Encoder` and `Decoder` for the serialization format.
@ -112,9 +114,9 @@ defmodule RDF.Serialization.Format do
Module.get_attribute(__MODULE__, :extension) do
def extension, do: @extension
end
if !Module.defines?(__MODULE__, {:content_type, 0}) &&
Module.get_attribute(__MODULE__, :content_type) do
def content_type, do: @content_type
if !Module.defines?(__MODULE__, {:media_type, 0}) &&
Module.get_attribute(__MODULE__, :media_type) do
def media_type, do: @media_type
end
end
end

View file

@ -74,13 +74,13 @@ defmodule RDF.Serialization do
## Examples
iex> RDF.Serialization.format_by_content_type("text/turtle")
iex> RDF.Serialization.format_by_media_type("text/turtle")
RDF.Turtle
iex> RDF.Serialization.format_by_content_type("application/ld+json")
iex> RDF.Serialization.format_by_media_type("application/ld+json")
nil # unless json_ld is defined as a dependency of the application
"""
def format_by_content_type(content_type) do
format_where(fn format -> format.content_type == content_type end)
def format_by_media_type(media_type) do
format_where(fn format -> format.media_type == media_type end)
end
@doc """

View file

@ -17,9 +17,9 @@ defmodule RDF.NQuads do
import RDF.Sigils
@id ~I<http://www.w3.org/ns/formats/N-Quads>
@name :nquads
@extension "nq"
@content_type "application/n-quads"
@id ~I<http://www.w3.org/ns/formats/N-Quads>
@name :nquads
@extension "nq"
@media_type "application/n-quads"
end

View file

@ -19,9 +19,9 @@ defmodule RDF.NTriples do
import RDF.Sigils
@id ~I<http://www.w3.org/ns/formats/N-Triples>
@name :ntriples
@extension "nt"
@content_type "application/n-triples"
@id ~I<http://www.w3.org/ns/formats/N-Triples>
@name :ntriples
@extension "nt"
@media_type "application/n-triples"
end

View file

@ -10,9 +10,9 @@ defmodule RDF.Turtle do
import RDF.Sigils
@id ~I<http://www.w3.org/ns/formats/Turtle>
@name :turtle
@extension "ttl"
@content_type "text/turtle"
@id ~I<http://www.w3.org/ns/formats/Turtle>
@name :turtle
@extension "ttl"
@media_type "text/turtle"
end