JViewer (JViewer v0.1.3) View Source
JViewer is an excellent way to declaratively represent elixir data in a JSON encodable format.
Link to this section Summary
Functions
Puts handler in schema's field under given path.
Puts handler_params in schema's field under given path.
Represents data in a JSON encodable format according to schema.
Link to this section Types
Specs
schema() :: JViewer.Types.Object.t()
Link to this section Functions
Specs
Specs
Specs
Specs
Specs
Specs
Puts handler in schema's field under given path.
If path cannot be followed, an exception is thrown.
Example
iex> import JViewer
...>
iex> schema =
iex> object(
iex> fields: [
iex> field(
iex> key: "product",
iex> type: object(
iex> fields: [
iex> field(
iex> key: "price",
iex> )
iex> ]
iex> )
iex> )
iex> ]
iex> )
...>
iex> put_handler(schema, ["product", "price"], &Map.get/2)
object(
fields: [
field(
key: "product",
type: object(
fields: [
field(
key: "price",
handler: &Map.get/2
)
]
)
)
]
)
Specs
Puts handler_params in schema's field under given path.
If path cannot be followed, an exception is thrown.
Example
iex> import JViewer
...>
iex> schema =
iex> object(
iex> fields: [
iex> field(
iex> key: "product",
iex> type: object(
iex> fields: [
iex> field(
iex> key: "price",
iex> handler: &Map.get/2
iex> )
iex> ]
iex> )
iex> )
iex> ]
iex> )
...>
iex> put_handler_params(schema, ["product", "price"], :price)
object(
fields: [
field(
key: "product",
type: object(
fields: [
field(
key: "price",
handler: &Map.get/2,
handler_params: :price
)
]
)
)
]
)
Specs
Represents data in a JSON encodable format according to schema.
If data cannot be represented, an exception is thrown.
Example
iex> import JViewer
...>
iex> schema =
iex> object(
iex> fields: [
iex> field(
iex> key: "id",
iex> type: number()
iex> ),
iex> field(
iex> key: "title",
iex> type: string()
iex> )
iex> ]
iex> )
...>
iex> data = %{
iex> id: 1,
iex> info: "I ate bread for breakfast",
iex> title: "Notes"
iex> }
...>
iex> represent(data, schema)
%{
"id" => 1,
"title" => "Notes"
}