module Amber::Schema::TypeCoercion

Defined in:

amber/schema/type_coercion.cr

Constant Summary

FALSE_VALUES = {"false", "0", "no", "n", "off", "f", "disabled", "inactive"}
TIME_FORMATS = ["%Y-%m-%dT%H:%M:%S.%LZ", "%Y-%m-%dT%H:%M:%S.%L%:z", "%Y-%m-%dT%H:%M:%S%:z", "%Y-%m-%dT%H:%M:%SZ", "%Y-%m-%d %H:%M:%S", "%Y-%m-%d %H:%M:%S %z", "%Y-%m-%d %H:%M:%S.%L", "%Y/%m/%d %H:%M:%S", "%Y-%m-%d", "%Y/%m/%d", "%m/%d/%Y %H:%M:%S", "%d/%m/%Y %H:%M:%S", "%m-%d-%Y", "%d-%m-%Y", "%m/%d/%Y", "%d/%m/%Y"]

Common time formats for parsing

TRUE_VALUES = {"true", "1", "yes", "y", "on", "t", "enabled", "active"}

Common boolean string representations

Class Method Summary

Class Method Detail

def self.can_coerce?(value : JSON::Any, target_type : String) : Bool #

Utility method to check if a value can be coerced to a type


[View source]
def self.clear_custom_coercions #

Clear all custom coercions


[View source]
def self.coerce(value : JSON::Any, target_type : String) : JSON::Any | Nil #

Main coercion method


[View source]
def self.coercion_error(field : String, value : JSON::Any, target_type : String) : CoercionError #

Get a descriptive error for a failed coercion


[View source]
def self.register(type : String, &block : JSON::Any -> JSON::Any | Nil) #

Register a custom coercion function for a type


[View source]