View Source Bonfire.Common.ContextModules (bonfire v0.3.5-classic-beta.10)

A Global cache of known context modules to be queried by associated schema, or vice versa.

Use of the ContextModules Service requires:

  1. Exporting context_module/0 in relevant modules (in schemas pointing to context modules and/or in context modules pointing to schemas), returning a Module atom
  2. To populate :bonfire, :context_modules_search_path in config the list of OTP applications where context_modules are declared.
  3. Start the Bonfire.Common.ContextModules application before querying.
  4. OTP 21.2 or greater, though we recommend using the most recent release available.

While this module is a GenServer, it is only responsible for setup of the cache and then exits with :ignore having done so. It is not recommended to restart the service as this will lead to a stop the world garbage collection of all processes and the copying of the entire cache to each process that has queried it since its last local garbage collection.

Link to this section Summary

Types

A query is either a context_module name atom or (Pointer) id binary

Functions

Returns a specification to start this module under a supervisor.

Look up a context, throw :not_found if not found.

Get a context identified by schema

Look up many contexts at once, throw :not_found if any of them are not found

Given an object or schema module name, run a function on the associated context module.

Populates the global cache with context_module data via introspection.

Link to this section Types

@type query() :: binary() | atom()

A query is either a context_module name atom or (Pointer) id binary

Link to this section Functions

Link to this function

apply_error(error, args)

View Source

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

context_function_error(error, args)

View Source

Look up a context, throw :not_found if not found.

@spec context_module(query :: query()) :: {:ok, atom()} | {:error, :not_found}

Get a context identified by schema

Link to this function

context_modules(modules)

View Source
@spec context_modules([binary() | atom()]) :: [binary()]

Look up many contexts at once, throw :not_found if any of them are not found

Link to this function

maybe_apply(object_schema_or_context, fun, args \\ [], fallback_fun \\ &apply_error/2)

View Source

Given an object or schema module name, run a function on the associated context module.

Link to this function

maybe_context_module(query)

View Source
Link to this function

search_app_modules(search_path \\ search_path())

View Source
@spec start_link(ignored :: term()) :: GenServer.on_start()

Populates the global cache with context_module data via introspection.