Dymo v1.0.3 Dymo.TaggerImpl View Source

This tagger helps with tagging objects using an ecto-backed 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, lbls, opts \\ [])

View Source

Adds labels to a given instance of a model.

Examples

iex> %Dymo.Post{title: "Hey"}
...>  |> Dymo.repo().insert!
...>  |> TaggerImpl.set_labels([{:number, "three"}, {:number, "four"}], create_missing: true)
...>  |> TaggerImpl.add_labels({:number, "five"}, create_missing: true)
...>  |> Map.get(:tags)
...>  |> Enum.map(& &1.label)
...>  |> Enum.sort()
~w(five four three)
Link to this function

all_labels(jt, jk, opts \\ [])

View Source
all_labels(join_table(), join_key(), keyword()) :: Ecto.Query.t()

Generates query for retrieving labels associated with a schema.

Examples

iex> %Dymo.Post{title: "Hey"}
...>  |> Dymo.repo().insert!
...>  |> TaggerImpl.set_labels([{:number, "eight"}, {:number, "nine"}], create_missing: true)
iex> "taggings"
...>  |> TaggerImpl.all_labels(:post_id, ns: :number)
...>  |> Dymo.repo().all()
["eight", "nine"]
Link to this function

labeled_with(module, label_or_labels, jt, jk, opts \\ [])

View Source

Queries models that are tagged with the given labels.

Examples

iex> %{id: id} = %Dymo.Post{title: "Hey"}
...>  |> Dymo.repo().insert!
...>  |> TaggerImpl.set_labels([{:number, "ten"}, {:number, "eleven"}], create_missing: true)
iex> id == Dymo.Post
...>  |> TaggerImpl.labeled_with({:number, "ten"}, "taggings", :post_id)
...>  |> Dymo.repo().all()
...>  |> hd
...>  |> Map.get(:id)
true
iex> Dymo.Post
...>  |> TaggerImpl.labeled_with({:unknown, "nothing"}, "taggings", :post_id)
...>  |> Dymo.repo().all()
[]
Link to this function

labels(struct, jt, jk, opts \\ [])

View Source

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

Link to this function

remove_labels(struct, lbls, opts \\ [])

View Source

Removes labels from a given instance of a model.

Examples

iex> %{tags: tags} = %Dymo.Post{title: "Hey"}
...>  |> Dymo.repo().insert!
...>  |> TaggerImpl.set_labels([{:number, "six"}, {:number, "seven"}], create_missing: true)
...>  |> TaggerImpl.remove_labels({:number, "six"})
iex> Enum.map(tags, & &1.label)
["seven"]
Link to this function

set_labels(struct, label_or_labels, opts \\ [])

View Source

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> post = %Dymo.Post{title: "Hey"}
...>  |> Dymo.repo().insert!
iex> post
...>  |> TaggerImpl.set_labels([{:rank, "one"}, {:rank, "two"}], create_missing: true)
...>  |> Map.get(:tags)
...>  |> Enum.map(& {&1.ns, &1.label})
[{:rank, "one"}, {:rank, "two"}]
iex> post
...>  |> TaggerImpl.set_labels({:rank, "officer"}, create_missing: true)
...>  |> Map.get(:tags)
...>  |> Enum.map(& {&1.ns, &1.label})
[{:rank, "officer"}]