module
ActiveModel::Sanitizer
Defined in:
active-model/sanitizer.crClass Method Summary
- .basic
- .common
- .inline
-
.sanitize(value : Array(T), policy : Symbol) : Array(T) forall T
Recursive Array(T) — dispatches to the appropriate
.sanitizefor each element. -
.sanitize(value : Set(T), policy : Symbol) : Set(T) forall T
Recursive Set(T).
-
.sanitize(value : Hash(K, V), policy : Symbol) : Hash(K, V) forall K, V
Recursive Hash.
-
.sanitize(value : String, policy : Symbol) : String
Base case: a single String.
-
.sanitize(value : JSON::Any, policy : Symbol) : JSON::Any
JSON::Any — walk the tree, sanitize string leaves only.
-
.sanitize(value : ActiveModel::Sanitizable, policy : Symbol)
User-defined types opt in by including
ActiveModel::Sanitizable. -
.sanitize(value, policy : Symbol)
Catch-all for union types.
- .text
Class Method Detail
Recursive Array(T) — dispatches to the appropriate .sanitize for each element.
Recursive Set(T).
NOTE post-sanitize de-duplication may shrink the set when two distinct
input values collapse to the same sanitized value (e.g. :text turns
both "<b>x</b>" and "x" into "x"). Use Array(T) if order/length
must be preserved.
Recursive Hash. Keys are identifiers and are not sanitized, so K can be any type; only V is walked.
JSON::Any — walk the tree, sanitize string leaves only. Non-string scalars (Int64, Float64, Bool, Nil) pass through untouched.
User-defined types opt in by including ActiveModel::Sanitizable.
Catch-all for union types. The strongly-typed overloads above win for
concrete static types; this fires only when value's compile-time type
is a union — which the macro walker has verified contains at least one
sanitizable arm. Used both for top-level union attributes (e.g.
String | Int32) and for union elements inside accepted containers
(e.g. Array(String | Int32)). The recursive .sanitize(value, policy)
calls dispatch back to the strongly-typed overloads because Crystal
narrows value's type inside each is_a? branch.