AshBackpex.Config (Ash Backpex v0.1.7)
View SourceConfiguration helpers for AshBackpex.
This module provides functions to read AshBackpex configuration from the application environment. Configuration can be set at two levels with the following precedence:
App-scoped config (highest priority):
config :my_app, AshBackpex, field_type_mappings: %{...}Global config (fallback):
config :ash_backpex, field_type_mappings: %{...}
Example
In your config/config.exs:
# Global config (applies to all apps using AshBackpex)
config :ash_backpex,
field_type_mappings: %{
MyApp.Types.Money => Backpex.Fields.Currency
}
# App-specific config (overrides global for this app)
config :my_app, AshBackpex,
field_type_mappings: %{
MyApp.Types.Money => MyApp.Fields.MoneyField
}
Summary
Functions
Reads the field type mappings configuration.
Validates that a field_type_mappings config value has the correct format.
Functions
Reads the field type mappings configuration.
Checks app-scoped config first (e.g., config :my_app, AshBackpex, field_type_mappings: ...),
then falls back to global config (config :ash_backpex, field_type_mappings: ...).
Returns nil if no configuration is found.
Parameters
otp_app- The OTP application name to check for app-scoped config. Ifnil, only checks global config.
Examples
# With app-scoped config
iex> AshBackpex.Config.field_type_mappings(:my_app)
%{MyApp.Types.Money => Backpex.Fields.Currency}
# No config set
iex> AshBackpex.Config.field_type_mappings(:my_app)
nil
Validates that a field_type_mappings config value has the correct format.
Valid formats:
- A map where keys are Ash type modules (atoms) or tuple types like
{:array, Ash.Type.String} - A function with arity 2 that takes
(type, constraints)and returns a Backpex field module or nil
Raises a clear error message if the config format is invalid.
Examples
# Valid map
iex> AshBackpex.Config.validate_field_type_mappings!(%{Ash.Type.String => Backpex.Fields.Textarea})
%{Ash.Type.String => Backpex.Fields.Textarea}
# Valid function
iex> fun = fn _type, _constraints -> nil end
iex> AshBackpex.Config.validate_field_type_mappings!(fun)
fun
# Invalid: not a map or function
iex> AshBackpex.Config.validate_field_type_mappings!("invalid")
** (ArgumentError) Invalid field_type_mappings configuration...