MishkaCmsCore.ProviderRegistry (Mishka CMS Core v0.0.1)

Copy Markdown View Source

Providers as mishka_installer plugins — the half MishkaCmsCore.Mail.Provider and MishkaCmsCore.Captcha.Provider share.

A provider is a module that listens on its kind's event and adds itself to the providers list the event carries. use makes a module that plugin:

use MishkaCmsCore.ProviderRegistry, event: "mail:providers", priority: 10

all/2, offered/2 and fetch/3 ask the event which providers are installed: every registered module that implements the kind's behaviour, the first of each id. Stopping a provider's plugin in the installer takes it out of the list. Nothing is cached: the event is asked each time.

An event whose plugins cannot run — one of them is not loaded, so Hook.call/3 answers its cannot_run: option — cannot say which providers are installed: all/2 and offered/2 list none, and fetch/3 answers {:error, :cannot_run} rather than {:error, :unknown_provider}.

Summary

Functions

Every provider registered on event that implements behaviour, the first of each id.

The offered provider registered on event under id; {:error, :cannot_run} when the event's plugins cannot run, so whether it is installed cannot be told.

The providers of all/2 this installation offers: every one, unless its offered?/0 says not.

Functions

all(event, behaviour)

@spec all(String.t(), module()) :: [module()]

Every provider registered on event that implements behaviour, the first of each id.

fetch(event, behaviour, id)

@spec fetch(String.t(), module(), String.t() | nil) ::
  {:ok, module()} | {:error, :unknown_provider | :cannot_run}

The offered provider registered on event under id; {:error, :cannot_run} when the event's plugins cannot run, so whether it is installed cannot be told.

offered(event, behaviour)

@spec offered(String.t(), module()) :: [module()]

The providers of all/2 this installation offers: every one, unless its offered?/0 says not.