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

Functions

Use this module to implements alternative Ecto.Tagger

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

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

Link to this section Types

Link to this type join_key() View Source
join_key() :: atom()

A join key is an atom.

Link to this type join_table() View Source
join_table() :: String.t()

A join table name is a string.

Link to this section Functions

Link to this macro __using__(opts) View Source (macro)

Use this module to implements alternative Ecto.Tagger

By default, all functions are delegated to Ecto.Tagger but can be overriden

Link to this function join_key(module) View Source
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
Link to this function join_table(module) View Source
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"
Link to this function singularize(target) View Source
singularize(Ecto.Schema.t() | module() | String.t()) :: String.t()

Link to this section Callbacks

Adds labels to a given instance of a model.

See Dymo.TaggerImpl.add_labels/{2,3}.

Link to this callback query_all_labels(join_table, join_key) View Source
query_all_labels(join_table(), join_key()) :: Ecto.Query.t()

Generates query for retrieving labels associated with a schema.

See Dymo.TaggerImpl.query_all_labels/{2,3}.

Link to this callback query_all_labels(join_table, join_key, arg2) View Source
query_all_labels(join_table(), join_key(), Dymo.Tag.ns()) :: Ecto.Query.t()
Link to this callback query_labeled_with(module, arg1, join_table, join_key) View Source
query_labeled_with(module(), Dymo.Tag.tag_or_tags(), join_table(), join_key()) ::
  Ecto.Query.t()

Queries models that are tagged with the given labels.

See Dymo.query_labeled_with.query_labels/4.

Link to this callback query_labels(arg0, join_table, join_key) View Source
query_labels(Ecto.Schema.t(), join_table(), join_key()) :: Ecto.Query.t()

Generates query for retrieving labels associated with a schema’s instance.

See Dymo.TaggerImpl.query_labels/{3,4}.

Link to this callback query_labels(arg0, join_table, join_key, arg3) View Source
query_labels(Ecto.Schema.t(), join_table(), join_key(), Dymo.Tag.ns()) ::
  Ecto.Query.t()

Removes labels from a given instance of a model.

See Dymo.TaggerImpl.remove_labels/{2,3}.

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.

See Dymo.TaggerImpl.set_labels/{2,3}.