abstract class Schematics::Model

Overview

Model base class

Simpler implementation using explicit field registration Example:

class User < Schematics::Model
  field email, String, required: true, validators: [min_length(5)]
  field age, Int32, default: 0, validators: [gte(0)]
end

Defined in:

model.cr

Macro Summary

Instance Method Summary

Macro Detail

macro field(name, type, required = false, default = nil, validators = nil) #

Field definition macro - simpler approach


[View source]

Instance Method Detail

def errors : Hash(Symbol, Array(String)) #

[View source]
abstract def to_h : Hash(String, JSON::Any) #

Convert to hash


[View source]
def to_json(io : IO) : Nil #

Convert to JSON


[View source]
def to_json : String #

[View source]
def valid? : Bool #

Check if model is valid


[View source]
def validate! : Bool #

Validate and raise if invalid


[View source]
def validate_model #

Override this for custom validations


[View source]