class Tarot::Schema

Defined in:

tarot/schema.cr
tarot/schema/converters.cr
tarot/schema/errors.cr
tarot/schema/validators.cr

Constant Summary

KEYS = {} of Nil => Nil
RULES = [] of Nil
VERSION = "0.2.0"

Constructors

Class Method Summary

Macro Summary

Instance Method Summary

Constructor Detail

def self.new(raw_fields : JSON::Any) #

[View source]
def self.new(parser : JSON::PullParser) #

[View source]
def self.new(**tuple) #

[View source]

Class Method Detail

def self.from_json(value : JSON::Any, hint = nil, coercive = false) #

[View source]
def self.from_json(parser : JSON::PullParser) #

[View source]
def self.from_json(string : String) #

[View source]
def self.from_json(any) #

[View source]
def self.from_json(**tuple) #

[View source]

Macro Detail

macro _build_to_json #

[View source]
macro _build_to_tuple #

[View source]
macro _build_validate #

[View source]
macro factory(on, map, fallback = false) #

Generate a factory for inherited schema, which bind the value of the field on to a specific subclass defined by the tuple:

  Event.factory("type", {"google": GoogleEvent, "facebook" : FacebookEvent})

Therefore, when using Event.from_json(json), this will create GoogleEvent or FacebookEvent.


[View source]
macro field(name_and_type, converter = nil, key = nil, hint = nil, emit_null = false, coercive = false) #

[View source]
macro rule(field, message, &block) #

[View source]
macro schema(name, optional = false, type = :record) #

[View source]

Instance Method Detail

def [](field : String) #

[View source]
def []?(field : String) #

[View source]
def add_error(key : String, error : String) #

[View source]
def errors : Hash(String, Array(String)) | Nil #

[View source]
def errors? : Hash(String, Array(String)) | Nil | Nil #

[View source]
def field_valid?(field) #

[View source]
def raw_fields : JSON::Any #

[View source]
def valid! #

[View source]
def valid? #

[View source]
def validate_nested(root : String, value) #

[View source]