Dymo v0.1.1 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
Queries models that are tagged with the given labels
Callback implementation for Dymo.Tagger.query_labeled_with/4
Removes labels from a given instance of a model
Callback implementation for Dymo.Tagger.query_labels/3
Removes labels from a given instance of a model
Sets the labels associated with an instance of a model
Link to this section Types
Link to this section Functions
add_labels(Ecto.Schema.t(), label() | 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(labels)
...> |> TaggerImpl.add_labels("five")
iex> Enum.map(tags, & &1.label)
["three", "four", "five"]
query_labeled_with(module(), label() | labels()) :: 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(labels)
iex> id == Dymo.Post
...> |> TaggerImpl.query_labeled_with(labels)
...> |> Dymo.repo().all()
...> |> hd
...> |> Map.get(:id)
true
iex> id == Dymo.Post
...> |> TaggerImpl.query_labeled_with("ten")
...> |> Dymo.repo().all()
...> |> hd
...> |> Map.get(:id)
true
iex> id == Dymo.Post
...> |> TaggerImpl.query_labeled_with("one")
...> |> Dymo.repo().all()
...> |> hd
...> |> Map.get(:id)
false
query_labeled_with(module(), label() | labels(), join_table(), join_key()) :: Ecto.Query.t()
Callback implementation for Dymo.Tagger.query_labeled_with/4
.
query_labels(module() | String.t() | Ecto.Schema.t()) :: Ecto.Query.t()
Removes labels from a given instance of a model.
Examples
iex> labels = ~w(eight nine)
iex> post = %Dymo.Post{title: "Hey"}
...> |> Dymo.repo().insert!
iex> TaggerImpl.set_labels(post, labels)
iex> Dymo.Post
...> |> TaggerImpl.query_labels()
...> |> Dymo.repo().all()
...> |> Enum.empty?
false
iex> "posts_tags"
...> |> TaggerImpl.query_labels()
...> |> Dymo.repo().all()
...> |> Enum.empty?
false
iex> post
...> |> TaggerImpl.query_labels()
...> |> Dymo.repo().all()
["eight", "nine"]
iex> post
...> |> TaggerImpl.query_labels("posts_tags", :post_id)
...> |> Dymo.repo().all()
["eight", "nine"]
query_labels(Ecto.Schema.t(), String.t(), atom()) :: Ecto.Query.t()
Callback implementation for Dymo.Tagger.query_labels/3
.
remove_labels(Ecto.Schema.t(), label() | 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(labels)
...> |> TaggerImpl.remove_labels("six")
iex> Enum.map(tags, & &1.label)
["seven"]
set_labels(Ecto.Schema.t(), label() | labels()) :: Ecto.Schema.t()
Sets the labels associated with an instance of a model.
If any other labels are associated to the given model, they are discarded if they are not part of the list of passed new labels.
Examples
iex> labels = ~w(one two)
iex> %{tags: tags} = %Dymo.Post{title: "Hey"}
...> |> Dymo.repo().insert!
...> |> TaggerImpl.set_labels(labels)
iex> Enum.map(tags, & &1.label)
["one", "two"]