Current section

39 Versions

Jump to

Compare versions

6 files changed
+45 additions
-2 deletions
  @@ -35,4 +35,4 @@
35 35 [{<<"app">>,<<"uri_template">>},
36 36 {<<"optional">>,false},
37 37 {<<"requirement">>,<<"~>1.0">>}]}]}.
38 - {<<"version">>,<<"4.9.0">>}.
38 + {<<"version">>,<<"4.10.0">>}.
  @@ -3,6 +3,8 @@ defmodule ExHal.Document do
3 3 A document is the representaion of a single resource in HAL.
4 4 """
5 5
6 + @type t :: %__MODULE__{}
7 +
6 8 alias ExHal.Link
7 9 alias ExHal.NsReg
  @@ -1,3 +1,4 @@
1 1 defprotocol ExHal.Locatable do
2 + @spec url(any) :: {:ok, String.t} | :error
2 3 def url(thing)
3 4 end
  @@ -71,6 +71,29 @@ defmodule ExHal.Transcoder do
71 71 ```
72 72 """
73 73
74 + @type t :: module
75 +
76 + @callbackdoc"""
77 + Returns a decoded version of HAL document merged with the initial params.
78 +
79 + initial_params - the initial params with which the newly extracted info should
80 + merged.
81 + src_doc - the document to interpret
82 + """
83 + @callback decode!(%{}, ExHal.Document.t) :: %{}
84 + @callback decode!(ExHal.Document.t) :: %{}
85 +
86 + @callbackdoc"""
87 + Returns an HAL version of params provided, combined with the initial doc.
88 +
89 + initial_doc - the initial document with which the newly encoded info should
90 + merged.
91 + src_params - the params to encoded into HAL
92 + """
93 + @callback encode!(Exhal.Document.t, %{}) :: ExHal.Document.t
94 + @callback encode!(%{}) :: ExHal.Document.t
95 +
96 +
74 97 defmacro __using__(_opts) do
75 98 quote do
76 99 import unquote(__MODULE__)
  @@ -84,6 +107,8 @@ defmodule ExHal.Transcoder do
84 107
85 108 defmacro __before_compile__(_env) do
86 109 quote do
110 + @behaviour ExHal.Transcoder
111 +
87 112 def decode!(doc), do: decode!(%{}, doc)
88 113 def decode!(initial_params, doc) do
89 114 @extractors
  @@ -99,7 +124,20 @@ defmodule ExHal.Transcoder do
99 124 end
100 125
101 126 defmodule ValueConverter do
127 + @type t :: module
128 +
129 + @callbackdoc"""
130 + Returns Elixir representation of HAL value.
131 +
132 + hal_value - The HAL representation of the value to convert.
133 + """
102 134 @callback from_hal(any) :: any
135 +
136 + @callbackdoc"""
137 + Returns HAL representation of Elixir value.
138 +
139 + elixir_value - The Elixir representation of the value to convert.
140 + """
103 141 @callback to_hal(any) :: any
104 142 end
  @@ -4,7 +4,7 @@ defmodule ExHal.Mixfile do
4 4 def project do
5 5 [app: :exhal,
6 6 description: "Use HAL APIs with ease",
7 - version: "4.9.0",
7 + version: "4.10.0",
8 8 elixir: "~> 1.2",
9 9
10 10 test_coverage: [tool: ExCoveralls],
  @@ -28,6 +28,7 @@ defmodule ExHal.Mixfile do
28 28
29 29 {:earmark, ">= 0.0.0", only: :dev},
30 30 {:ex_doc, "~> 0.11", only: :dev},
31 + {:dialyxir, "~> 0.3", only: :dev},
31 32
32 33 {:exvcr, "~> 0.7", only: :test},
33 34 {:excoveralls, "~> 0.4", only: :test}
Loading more files…