Built-in sanitizer ops. Every clause follows the pipe-friendly
sanitize(value, op) argument order:
" Hello " |> SanitizerDerive.sanitize(:trim) |> SanitizerDerive.sanitize(:downcase)
# => "hello"An op is served by the first that knows it: the built-in ops, then the derive
extensions of the module being built, then its sanitize_derive modules in order.
A sanitize_derive module passes an op on to the next one by returning nil, or
by having no sanitize/2 clause that matches the value and the op.
Sanitizing fails closed:
- a sanitizer that raises never lets the raw value through. In a
derivesstring the field fails with a:sanitizeerror and the exception is logged (seecall/2);sanitize/2raises the exception. - an op that nothing serves raises
ArgumentError, because the op is a programming mistake.
Summary
Functions
Runs the sanitize ops of a field in order and returns {field, value}.
Applies one sanitize op to input. Raises what the sanitizer raises, and
ArgumentError for an op that nothing serves.
Functions
Runs the sanitize ops of a field in order and returns {field, value}.
When a sanitizer raises, value is the field's :sanitize error
({:error, field, :sanitize, message}), which
GuardedStruct.Derive.ValidationDerive.call/3 reports like any other field
error. The exception is logged at error level with its stacktrace, without the
arguments of each call, so the value itself is never logged.
Applies one sanitize op to input. Raises what the sanitizer raises, and
ArgumentError for an op that nothing serves.