Configuration

v0.1.4

This page lists the application config keys of GuardedStruct 0.1.4, the options of use GuardedStruct, the packages that some features need, and the callbacks that produce error messages.

Application config

Set these under config :guarded_struct.

KeyValueDefaultEffect
derive_extensionsList of modules[]Extension modules whose ops every guarded module can use. See Add your own derive ops. The list is read at run time and cached.
validate_deriveModule or list of modulesnoneFallback modules for validate ops. Each defines validate(op, value, field). Read at run time. The validate_derive option of the guardedstruct section is tried first.
sanitize_deriveModule or list of modulesnoneFallback modules for sanitize ops. Each defines sanitize(value, op). Read at run time. The sanitize_derive option of the guardedstruct section is tried first.
message_backendModuleGuardedStruct.MessagesThe module that returns every error message. Read when GuardedStruct compiles.
elixir
# config/config.exs
config :guarded_struct,
  derive_extensions: [MyApp.Derives],
  validate_derive: [MyApp.MoreValidators],
  sanitize_derive: [MyApp.MoreSanitizers],
  message_backend: MyApp.Messages

Options of use GuardedStruct

OptionValueEffect
derive_extensionsList of modules, which can include :config onceChooses the extensions for this module. :config stands for the application config list. [] means none. A value that is not a list raises ArgumentError.

Packages

GuardedStruct 0.1.4 needs Elixir 1.17 or later. The first four packages in this table come with GuardedStruct. Add the others to your own deps when you use the feature next to them.

PackageVersion in mix.exsNeeded for
spark~> 2.7The DSL. Always installed.
splode~> 0.3GuardedStruct.Errors. Always installed.
telemetry~> 1.0Build events. Always installed.
html_sanitize_ex~> 1.5The HTML sanitize ops. Always installed.
jason~> 1.4json: true, unless you use the built-in JSON module of Elixir 1.18 and later.
email_checker~> 0.2.4The email validate op.
ex_url~> 2.0.2The tell, geo_url and location validate ops.
ex_phone_number~> 0.4.11The tell=code form, together with ex_url.
ash~> 3.0The GuardedStruct.AshResource extension.
igniter~> 0.8.0mix igniter.install guarded_struct.

An optional package is looked up when the op runs, so the order of your dependencies does not matter, in mix.exs or in Mix.install. An op whose package is missing fails with its own name as the action, and the message names the package to add.

Message callbacks

A module that uses GuardedStruct.Messages gets a default for every callback, and you override the ones you want. Each callback returns a string.

CallbackArgumentMessage for
required_fields/0nonerequired_fields
authorized_fields/0noneauthorized_fields
builder/0nonebad_parameters
list_builder_type/0noneA list was expected for a list-valued child of a conditional field.
message_exception/0, message_exception/1none; the exceptionThe first line of the generated Error exception.
check_dependent_keys/1{field, path}, where path is a list of atomsdependent_keys
domain_field_status/1, force_domain_field_status/1The field namedomain_parameters, without and with a missing required path
is_type/1{field, type}The type ops such as string and integer.
max_len_binary/1, max_len_integer/1, max_len_range/1, max_len_list/1{field, length}max_len, by kind of value
min_len_binary/1, min_len_integer/1, min_len_range/1, min_len_list/1{field, length}min_len, by kind of value
max_len/1, min_len/1The field namemax_len or min_len written without a number
not_empty_binary/1, not_empty_list/1, not_empty_map/1, not_empty/1The field namenot_empty, by kind of value
url_scheme/1, url_host/1, url_gethostbyname/1, url/1The field nameurl, by the cause of the failure
convert_enum_output/1, enum/1The field nameenum, for a value outside the list and for a value of the wrong type
validate_unexpected/1The field nametype
date_binary/1The field namedate
location_url/1The field namegeo_url and location
Every other callbackThe field nameThe op with the same name: uuid/1, email_r/1, slug/1, hostname/1, port_number/1, semver/1, each/1, either/1, custom/1 and so on.

The behaviour also declares register_struct/0, list_builder/0, list_builder_field_exception/0, field/1 and field_type/1. Version 0.1.4 does not call them.