module ActiveModel::Sanitizer

Defined in:

active-model/sanitizer.cr

Class Method Summary

Class Method Detail

def self.basic #

[View source]
def self.common #

[View source]
def self.inline #

[View source]
def self.sanitize(value : Array(T), policy : Symbol) : Array(T) forall T #

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


[View source]
def self.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.


[View source]
def self.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.


[View source]
def self.sanitize(value : String, policy : Symbol) : String #

Base case: a single String.


[View source]
def self.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.


[View source]
def self.sanitize(value : ActiveModel::Sanitizable, policy : Symbol) #

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


[View source]
def self.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.


[View source]
def self.text #

[View source]