Dymo v0.3.4 Dymo.TaggerImpl View Source

This tagger helps with tagging objects using a backed ecto repo.

Link to this section Summary

Functions

Adds labels to a given instance of a model

Generates query for retrieving labels associated with a schema

Queries models that are tagged with the given labels

Generates query for retrieving labels associated with a schema’s instance

Removes labels from a given instance of a model

Sets the labels associated with an instance of a model, for the given namespace

Link to this section Types

Link to this section Functions

Link to this function add_labels(struct, ns \\ nil, lbls) View Source
add_labels(Dymo.Taggable.t(), Dymo.Tag.ns() | nil, String.t() | [String.t()]) ::
  Ecto.Schema.t()

Adds labels to a given instance of a model.

Examples

iex> labels = ~w(three four)
iex> %{tags: tags} = %Dymo.Post{title: "Hey"}
...>  |> Dymo.repo().insert!
...>  |> TaggerImpl.set_labels(:number, labels)
...>  |> TaggerImpl.add_labels(:number, "five")
iex> Enum.map(tags, & &1.label)
["three", "four", "five"]
Link to this function labels(struct, ns \\ nil) View Source
labels(Dymo.Taggable.t(), Dymo.Tag.ns() | nil) :: [Dymo.Tag.label()]
Link to this function query_all_labels(jt, jk, ns \\ nil) View Source
query_all_labels(join_table(), join_key(), Dymo.Tag.ns() | nil) ::
  Ecto.Query.t()

Generates query for retrieving labels associated with a schema.

Examples

iex> labels = ~w(eight nine)
iex> post = %Dymo.Post{title: "Hey"}
...>  |> Dymo.repo().insert!
...>  |> TaggerImpl.set_labels(:number, labels)
iex> "posts_tags"
...>  |> TaggerImpl.query_all_labels(:post_id, :number)
...>  |> Dymo.repo().all()
["eight", "nine"]
Link to this function query_labeled_with(module, label_or_labels, jt, jk) View Source
query_labeled_with(
  module(),
  Dymo.Tag.label_or_labels(),
  join_table(),
  join_key()
) :: Ecto.Query.t()

Queries models that are tagged with the given labels.

Examples

iex> labels = ~w(ten eleven)
iex> %{id: id} = %Dymo.Post{title: "Hey"}
...>  |> Dymo.repo().insert!
...>  |> TaggerImpl.set_labels(:number, labels)
iex> id == Dymo.Post
...>  |> TaggerImpl.query_labeled_with({:number, "ten"}, "posts_tags", :post_id)
...>  |> Dymo.repo().all()
...>  |> hd
...>  |> Map.get(:id)
true
iex> Dymo.Post
...>  |> TaggerImpl.query_labeled_with({:unknown, "nothing"}, "posts_tags", :post_id)
...>  |> Dymo.repo().all()
[]
Link to this function query_labels(struct, jt, jk, ns \\ nil) View Source
query_labels(Dymo.Taggable.t(), join_table(), join_key(), Dymo.Tag.ns() | nil) ::
  Ecto.Query.t()

Generates query for retrieving labels associated with a schema’s instance.

Link to this function remove_labels(struct, ns \\ nil, lbls) View Source
remove_labels(Dymo.Taggable.t(), Dymo.Tag.ns() | nil, String.t() | [String.t()]) ::
  Ecto.Schema.t()

Removes labels from a given instance of a model.

Examples

iex> labels = ~w(six seven)
iex> %{tags: tags} = %Dymo.Post{title: "Hey"}
...>  |> Dymo.repo().insert!
...>  |> TaggerImpl.set_labels(:number, labels)
...>  |> TaggerImpl.remove_labels(:number, "six")
iex> Enum.map(tags, & &1.label)
["seven"]
Link to this function set_labels(struct, ns \\ nil, lbls) View Source
set_labels(Dymo.Taggable.t(), Dymo.Tag.ns() | nil, String.t() | [String.t()]) ::
  Ecto.Schema.t()

Sets the labels associated with an instance of a model, for the given namespace.

If any other labels are associated to the given model and namespace, they are discarded if they are not part of the list of passed new labels.

Examples

iex> labels = ~w(one two)
iex> post = %Dymo.Post{title: "Hey"}
iex> %{tags: tags} =
...>  post
...>  |> Dymo.repo().insert!
...>  |> TaggerImpl.set_labels(:rank, labels)
iex> Enum.map(tags, & &1.label)
["one", "two"]