module

ActiveModel::Sanitizer

Class methods

basic
Source
common
Source
inline
Source
sanitize(value : Array(T), policy : Symbol) : Array(T) forall T

Recursive Array(T) — dispatches to the appropriate sanitize for each element.

Source
sanitize(value : Set(T), policy : Symbol) : Set(T) forall T

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.

Source
sanitize(value : Hash(K, V), policy : Symbol) : Hash(K, V) forall K, V

Recursive Hash. Keys are identifiers and are not sanitized, so K can be any type; only V is walked.

Source
sanitize(value : String, policy : Symbol) : String

Base case: a single String.

Source
sanitize(value : JSON::Any, policy : Symbol) : JSON::Any

JSON::Any — walk the tree, sanitize string leaves only. Non-string scalars (Int64, Float64, Bool, Nil) pass through untouched.

Source
sanitize(value : ActiveModel::Sanitizable, policy : Symbol)

User-defined types opt in by including ActiveModel::Sanitizable.

Source
sanitize(value, policy : Symbol)

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.

Source
text
Source