abstract class
Schematics::Model
- Schematics::Model
- Reference
- Object
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.crMacro Summary
-
field(name, type, required = false, default = nil, validators = nil)
Field definition macro - simpler approach
Instance Method Summary
- #errors : Hash(Symbol, Array(String))
-
#to_h : Hash(String, JSON::Any)
Convert to hash
-
#to_json(io : IO) : Nil
Convert to JSON
- #to_json : String
-
#valid? : Bool
Check if model is valid
-
#validate! : Bool
Validate and raise if invalid
-
#validate_model
Override this for custom validations
Macro Detail
Field definition macro - simpler approach