From eb6ede55b9aa2797179c8905578492d9d5abfc58 Mon Sep 17 00:00:00 2001 From: Marcel Otto Date: Thu, 8 Mar 2018 02:14:49 +0100 Subject: [PATCH] Rename RDF.Serialization.Format.content_type/0 to media_type/0 --- CHANGELOG.md | 3 ++- lib/rdf/serialization/format.ex | 30 ++++++++++++++------------ lib/rdf/serialization/serialization.ex | 8 +++---- lib/rdf/serializations/nquads.ex | 8 +++---- lib/rdf/serializations/ntriples.ex | 8 +++---- lib/rdf/serializations/turtle.ex | 8 +++---- 6 files changed, 34 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6ab945..27036ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` diff --git a/lib/rdf/serialization/format.ex b/lib/rdf/serialization/format.ex index 885b149..41c4d76 100644 --- a/lib/rdf/serialization/format.ex +++ b/lib/rdf/serialization/format.ex @@ -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 - @extension "ext" - @content_type "application/some-format" + @id ~I + @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 diff --git a/lib/rdf/serialization/serialization.ex b/lib/rdf/serialization/serialization.ex index 29d9a91..ec087f8 100644 --- a/lib/rdf/serialization/serialization.ex +++ b/lib/rdf/serialization/serialization.ex @@ -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 """ diff --git a/lib/rdf/serializations/nquads.ex b/lib/rdf/serializations/nquads.ex index 46e823e..d76e702 100644 --- a/lib/rdf/serializations/nquads.ex +++ b/lib/rdf/serializations/nquads.ex @@ -17,9 +17,9 @@ defmodule RDF.NQuads do import RDF.Sigils - @id ~I - @name :nquads - @extension "nq" - @content_type "application/n-quads" + @id ~I + @name :nquads + @extension "nq" + @media_type "application/n-quads" end diff --git a/lib/rdf/serializations/ntriples.ex b/lib/rdf/serializations/ntriples.ex index 300cb49..947d9d2 100644 --- a/lib/rdf/serializations/ntriples.ex +++ b/lib/rdf/serializations/ntriples.ex @@ -19,9 +19,9 @@ defmodule RDF.NTriples do import RDF.Sigils - @id ~I - @name :ntriples - @extension "nt" - @content_type "application/n-triples" + @id ~I + @name :ntriples + @extension "nt" + @media_type "application/n-triples" end diff --git a/lib/rdf/serializations/turtle.ex b/lib/rdf/serializations/turtle.ex index 3aa4dc2..53a9e44 100644 --- a/lib/rdf/serializations/turtle.ex +++ b/lib/rdf/serializations/turtle.ex @@ -10,9 +10,9 @@ defmodule RDF.Turtle do import RDF.Sigils - @id ~I - @name :turtle - @extension "ttl" - @content_type "text/turtle" + @id ~I + @name :turtle + @extension "ttl" + @media_type "text/turtle" end