Dymo v0.3.3 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
add_labels(Dymo.Taggable.t(), Dymo.Tag.ns() | nil, Dymo.Tag.label_or_labels()) :: 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"]
labels(Dymo.Taggable.t(), Dymo.Tag.ns() | nil) :: [Dymo.Tag.label()]
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"]
query_labeled_with(module(), Dymo.Tag.tag_or_tags(), 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()
[]
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.
remove_labels( Dymo.Taggable.t(), Dymo.Tag.ns() | nil, Dymo.Tag.label_or_labels() ) :: 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"]
set_labels(Dymo.Taggable.t(), Dymo.Tag.ns() | nil, Dymo.Tag.label_or_labels()) :: 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"]