Dymo v0.3.3 Dymo.Tag View Source
This module provides functionality dedicated to handling tag data.
It essentially aims at maintaining singleton labels in a tags
table
and exposes helper functions to ease their creation.
Link to this section Summary
Types
Defines attributes for building this model’s changeset
Defines a tag’s label
Defines a single flat label or a list of labels
Defines simple tags identified by a unique label
Defines alternative representations of a tag
Defines a single flat tag or a list of tags
Link to this section Types
Defines attributes for building this model’s changeset
Defines a tag’s label
Defines a single flat label or a list of labels.
Defines simple tags identified by a unique label.
Defines alternative representations of a tag
Defines a single flat tag or a list of tags.
Link to this section Functions
Makes a changeset suited to manipulate the Dymo.Tag
model.
Examples
iex> cs = changeset("blue")
...> with %Changeset{valid?: true} <- cs, do: :ok
:ok
iex> cs = changeset({:paint, "blue"})
...> with %Changeset{valid?: true} <- cs, do: :ok
:ok
iex> cs = changeset({[:paint, :car], "blue"})
...> with %Changeset{valid?: true} <- cs, do: :ok
:ok
iex> cs = changeset({"car", "blue"})
...> with %Changeset{valid?: false} <- cs, do: :error
:error
iex> cs = changeset(%{ns: :car, label: "blue"})
...> with %Changeset{valid?: true} <- cs, do: :ok
:ok
find_or_create!(tag_or_tags()) :: tag_or_tags()
This function gets an existing tag using its label. If the tag doesn’t exit, it is atomically created. It could be described as a “singleton” helper.
Examples
iex> %{id: id1a} = Tag.find_or_create!("novel")
...> [%{id: id2a}, %{id: id3a}] = Tag.find_or_create!(["article", "book"])
...> [%{id: id1b}, %{id: id2b}, %{id: id3b}] = Tag.find_or_create!(["novel", "article", "book"])
...> {id1a, id2a, id3a} == {id1b, id2b, id3b}
true
iex> %{id: id4a} = Tag.find_or_create!({:romance, "novel"})
...> [%{id: id5a}, %{id: id6a}] = Tag.find_or_create!([{:romance, "article"}, {:sf, "book"}])
...> [%{id: id4b}, %{id: id5b}, %{id: id6b}] = Tag.find_or_create!([{:romance, "novel"}, {:romance, "article"}, {:sf, "book"}])
...> {id4a, id5a, id6a} == {id4b, id5b, id6b}
true