View Source Bonfire.Common.Config (Bonfire v0.9.11-social-beta.6)

Helpers to get app/extension OTP config, or to override a config key. Basically a wrapper of Application.get_env/3 and Application.put_env/3.

Summary

Functions

Deletes the configuration value for a key in a specific OTP app or extension.

Retrieves the Phoenix endpoint module for the application.

Retrieves the environment configuration for the application.

Retrieves a configuration value for a key, optionally from a specific OTP app or extension.

Retrieves the configuration value for a key and raises an error if the value is not found.

Retrieves all configuration keys and values for a specific Bonfire extension or OTP app.

Retrieves a configuration value for a specific Bonfire extension or OTP app key.

Retrieves all configuration keys and values for a specific Bonfire extension or OTP app and raises an error if no configuration is found.

Retrieves the configuration value for a specific Bonfire extension or OTP app key and raises an error if the value is not found.

Constructs a key path for configuration settings, which always starts with an app or extension name. It starts with the main OTP app or extension and includes additional keys as specified.

Sets the configuration value for a key or key tree in a specific OTP app or extension.

Retrieves the Ecto repository module for the application.

Raises an error if the specified Bonfire extension is not configured.

Functions

compilation_error(error)

(macro)

delete(key, otp_app \\ top_level_otp_app())

Deletes the configuration value for a key in a specific OTP app or extension.

This function removes the configuration value for the given key from the specified OTP app or extension.

Examples

iex> delete(:key)
:ok

iex> delete([:nested, :key], :my_app)
:ok

endpoint_module()

Retrieves the Phoenix endpoint module for the application.

This function first attempts to fetch the Phoenix endpoint module from the :phoenix_endpoint_module key in the process dictionary. If not found, it retrieves the value from the application configuration, defaulting to Bonfire.Web.Endpoint if not configured.

Examples

iex> endpoint_module()
Bonfire.Web.Endpoint

env()

Retrieves the environment configuration for the application.

This function returns the value of the :env configuration key for the application.

Examples

iex> env()
:test

get(key_or_keys, default \\ nil, otp_app \\ nil)

Retrieves a configuration value for a key, optionally from a specific OTP app or extension.

This function can handle single keys or nested key trees and returns the configuration value associated with the key(s). It falls back to a default value if the key is not found.

Examples

iex> get(:test_key, "default")
"test_value"

iex> get([:nested, :key], "default", :bonfire)
"default"

iex> get(:missing_key, "default")
"default"

get!(key, otp_app \\ top_level_otp_app())

Retrieves the configuration value for a key and raises an error if the value is not found.

Examples

iex> get!(:test_key)
"test_value"

iex> get!(:missing_key, :bonfire_common)
** (Bonfire.Common.Config.Error) Missing configuration value: [:bonfire_common, :missing_key]

get_ext(module_or_otp_app)

Retrieves all configuration keys and values for a specific Bonfire extension or OTP app.

Examples

> get_ext(:my_extension)
[key1: "value1", key2: "value2"]

> get_ext(:another_extension)
[]

get_ext(module_or_otp_app, key, default \\ nil)

Retrieves a configuration value for a specific Bonfire extension or OTP app key.

This function attempts to get the configuration value for the given key from the specified extension or OTP app. If the key is not found, it falls back to checking the top-level Bonfire app configuration.

Examples

iex> get_ext(:bonfire_common, :test_key, "default")
"test_value"

iex> get_ext(:my_extension, :missing_key, "default")
"default"

get_ext!(module_or_otp_app)

Retrieves all configuration keys and values for a specific Bonfire extension or OTP app and raises an error if no configuration is found.

Examples

iex> config = get_ext!(:bonfire_common)
iex> is_list(config) and config !=[]
true

iex> get_ext!(:non_existent_extension)
** (Bonfire.Common.Config.Error) Empty configuration for extension: non_existent_extension

get_ext!(module_or_otp_app, key)

Retrieves the configuration value for a specific Bonfire extension or OTP app key and raises an error if the value is not found.

This function attempts to get the configuration value for the given key from the specified extension or OTP app. If the key is not present or the value is nil, it raises a compilation error.

Examples

iex> get_ext!(:bonfire_common, :test_key)
"test_value"

iex> get_ext!(:my_extension, :missing_key)
** (Bonfire.Common.Config.Error) Missing configuration value: [:my_extension, :missing_key]

get_for_process(keys)

keys_tree(keys)

Constructs a key path for configuration settings, which always starts with an app or extension name. It starts with the main OTP app or extension and includes additional keys as specified.

> keys_tree([:bonfire_me, Bonfire.Me.Users])
[:bonfire_me, Bonfire.Me.Users]

> keys_tree(Bonfire.Me.Users)
[:bonfire_me, Bonfire.Me.Users]

> keys_tree(:bonfire_me)
[:bonfire_me]

> keys_tree(:random_atom)
[:bonfire_common, :random_atom]

>keys_tree([:random_atom, :sub_key])
[:bonfire_common, :random_atom, :sub_key]

module_enabled?(module)

See Bonfire.Common.Extend.module_enabled?/1.

put(tree)

put(key, value, otp_app \\ nil)

Sets the configuration value for a key or key tree in a specific OTP app or extension.

This function allows you to set the configuration value for the specified key(s) in the given OTP app or extension. It supports nested configurations.

Examples

iex> put(:test_key, "test_value")
:ok

iex> put([:nested, :key], "test_value", :my_app)
:ok

repo()

Retrieves the Ecto repository module for the application.

This function first attempts to fetch the Ecto repository module from the :ecto_repo_module key in the process dictionary. If not found, it retrieves the value from the application configuration, and defaults to Bonfire.Common.Repo if not configured.

Examples

iex> repo()
Bonfire.Common.Repo

require_extension_config!(extension)

Raises an error if the specified Bonfire extension is not configured.

This function checks whether the configuration for a given Bonfire extension exists. If the configuration is missing, it raises a compilation error with a message indicating how to set up the configuration file.

Examples

iex> require_extension_config!(:some_extension)
** (Bonfire.Common.Config.Error) You have not configured the `some_extension` Bonfire extension, please `cp ./deps/some_extension/config/some_extension.exs ./config/some_extension.exs` in your Bonfire app repository and then customise the copied config as necessary

top_level_otp_app()