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
add_labels(struct, lbls, opts \\ [])
View Sourceadd_labels(Dymo.Taggable.t(), Dymo.Tag.label_or_labels(), keyword()) :: Ecto.Schema.t()
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)
all_labels(jt, jk, opts \\ [])
View Sourceall_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"]
labeled_with(module, label_or_labels, jt, jk, opts \\ [])
View Sourcelabeled_with( module(), Dymo.Tag.label_or_labels(), join_table(), join_key(), keyword() ) :: Ecto.Query.t()
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()
[]
labels(struct, jt, jk, opts \\ [])
View Sourcelabels(Dymo.Taggable.t(), join_table(), join_key(), keyword()) :: Ecto.Query.t()
Generates query for retrieving labels associated with a schema's instance.
remove_labels(struct, lbls, opts \\ [])
View Sourceremove_labels(Dymo.Taggable.t(), Dymo.Tag.label_or_labels(), keyword()) :: Ecto.Schema.t()
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"]
set_labels(struct, label_or_labels, opts \\ [])
View Sourceset_labels(Dymo.Taggable.t(), Dymo.Tag.label_or_labels(), keyword()) :: 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> 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"}]