View Source Bonfire.Common.Config (Bonfire v0.9.10-classic-beta.156)

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

Link to this macro

compilation_error(error)

View Source (macro)
Link to this function

delete(key, otp_app \\ top_level_otp_app())

View Source

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

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

Retrieves the environment configuration for the application.

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

Examples

iex> env()
:test
Link to this function

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

View Source

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"
Link to this function

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

View Source

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.Config.Error) Missing configuration value: [:bonfire, :missing_key]
Link to this function

get_ext(module_or_otp_app)

View Source

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)
[]
Link to this function

get_ext(module_or_otp_app, key, default \\ nil)

View Source

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"
Link to this function

get_ext!(module_or_otp_app)

View Source

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
Link to this function

get_ext!(module_or_otp_app, key)

View Source

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]

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]

iex> keys_tree(:random_atom)
[:bonfire, :random_atom]

iex>keys_tree([:random_atom, :sub_key])
[:bonfire, :random_atom, :sub_key]

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

Link to this function

put(key, value, otp_app \\ nil)

View Source

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

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
Link to this function

require_extension_config!(extension)

View Source

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