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

Queries models that are tagged with the given labels

Queries models that are tagged with the given labels

Retrieves labels associated with an target. The target could be either a module or a schema

Retrieves labels associated with an target

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

Link to this function add_labels(struct, lbls) View Source
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"]
Link to this function query_labeled_with(module, lbl_or_lbls) View Source
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> Dymo.Post
...>  |> TaggerImpl.query_labeled_with("noithing")
...>  |> Dymo.repo().all()
[]
Link to this function query_labeled_with(module, lbl_or_lbls, join_table, join_key) View Source
query_labeled_with(module(), label() | labels(), join_table(), join_key()) ::
  Ecto.Query.t()

Queries models that are tagged with the given labels.

See Dymo.query_labeled_with.query_labels/4.

Callback implementation for Dymo.Tagger.query_labeled_with/4.

Link to this function query_labels(module) View Source
query_labels(module() | String.t() | Ecto.Schema.t()) :: Ecto.Query.t()

Retrieves labels associated with an target. The target could be either a module or a schema.

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"]
Link to this function query_labels(map, join_table, join_key) View Source
query_labels(Ecto.Schema.t(), String.t(), atom()) :: Ecto.Query.t()

Retrieves labels associated with an target.

See query_labels/1

Link to this function remove_labels(struct, lbls) View Source
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"]
Link to this function set_labels(struct, lbls) View Source
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"]