Dymo v0.3.4 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

t()

Defines simple tags identified by a unique label

Functions

Makes a changeset suited to manipulate the Dymo.Tag model

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

Link to this section Types

Link to this type attrs() View Source
attrs() :: %{:label => String.t(), optional(:ns) => ns()}

Defines attributes for building this model’s changeset

Defines a tag’s label

Link to this type label_or_labels() View Source
label_or_labels() :: label() | [label()]

Defines a single flat label or a list of labels.

Link to this type t() View Source
t() :: %Dymo.Tag{
  __meta__: term(),
  id: term(),
  inserted_at: term(),
  label: term(),
  ns: term(),
  updated_at: term()
}

Defines simple tags identified by a unique label.

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
Link to this function find_or_create!(tags) View Source
find_or_create!(label_or_labels()) :: label_or_labels()

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