Dymo v0.1.3 Dymo.Tagger behaviour View Source
Defines the functions required for a tagger to be compabible with the Dymo.Taggable macro.
Link to this section Summary
Types
A join key is an atom
A join table name is a string
A single label is a string
Either a single label or a list of them
A list of labels
Functions
A helper function that helps computing the field name to use in taggings queries
A helper function that generates the join table name to be used for a given schema or model
Callbacks
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
A join key is an atom.
A join table name is a string.
A single label is a string.
Either a single label or a list of them.
A list of labels.
Link to this section Functions
join_key(Ecto.Schema.t() | module() | String.t()) :: atom()
A helper function that helps computing the field name to use in taggings queries.
Examples
iex> Tagger.join_key(Dymo.Post)
:post_id
iex> Tagger.join_key(%Dymo.Post{})
:post_id
iex> Tagger.join_key(Person)
:person_id
join_table(Ecto.Schema.t() | module() | String.t()) :: String.t()
A helper function that generates the join table name to be used for a given schema or model.
Examples
iex> Tagger.join_table(Dymo.Post)
"posts_tags"
iex> Tagger.join_table(%Dymo.Post{})
"posts_tags"
iex> Tagger.join_table(Person)
"people_tags"
singularize(Ecto.Schema.t() | module() | String.t()) :: String.t()
Link to this section Callbacks
add_labels(Ecto.Schema.t(), label_or_labels()) :: Ecto.Schema.t()
Adds labels to a given instance of a model.
query_labeled_with(module(), label_or_labels()) :: Ecto.Query.t()
Queries models that are tagged with the given labels.
See Dymo.query_labeled_with.query_labels/2
.
query_labeled_with(module(), label_or_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
.
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.
query_labels(Ecto.Schema.t(), join_table(), join_key()) :: Ecto.Query.t()
Retrieves labels associated with an target.
remove_labels(Ecto.Schema.t(), label_or_labels()) :: Ecto.Schema.t()
Removes labels from a given instance of a model.
set_labels(Ecto.Schema.t(), label_or_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.