class

Schematics::Model

Inherits Reference / Object

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

Instance methods

errors
Source
to_h

Convert to hash

Source
to_json(io : IO) : Nil

Convert to JSON

Source
to_json
Source
valid?

Check if model is valid

Source
validate!

Validate and raise if invalid

Source
validate_model

Override this for custom validations

Source

Macros

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

Field definition macro - simpler approach coerce: true enables automatic type coercion from compatible types

Source