Dymo v0.2.0 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
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
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(), 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(labels)
iex> id == Dymo.Post
...> |> TaggerImpl.query_labeled_with("ten", "posts_tags", :post_id)
...> |> Dymo.repo().all()
...> |> hd
...> |> Map.get(:id)
true
iex> Dymo.Post
...> |> TaggerImpl.query_labeled_with("nothing", "posts_tags", :post_id)
...> |> Dymo.repo().all()
[]
query_labels(join_table(), join_key()) :: 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!
...> |> TaggerImpl.set_labels(labels)
iex> "posts_tags"
...> |> TaggerImpl.query_labels(:post_id)
...> |> Dymo.repo().all()
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(), join_table(), join_key()) :: Ecto.Query.t()
Retrieves labels associated with an target.
See query_labels/1
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"]