module Quartz::Verifiable

Overview

Provides a runtime verification framework for your models.

Example:

class WeightModel
  include Quartz::Verifiable

  property weight : Float64 = 0.0 # in kg
  check :weight, numericality: {greater_than: 40, lesser_than: 160}
end

model = WeightModel.new
model.weight = 75.0
model.valid?   # => true
model.invalid? # => false

model.weight = 200.0
model.valid?          # => false
model.invalid?        # => true
model.errors.messages # => { :weight => ["must be lesser than 160"] }

Direct including types

Defined in:

quartz/verifiable.cr

Instance Method Summary

Instance Method Detail

def clear_errors #

Clears attribute error messages.


[View source]
def errors #

Returns the VerificationErrors object that holds all information about attribute error messages.


[View source]
def invalid?(context : Symbol? = nil) : Bool #

Performs the opposite of #valid?. Returns true if errors were added, false otherwise.

Usage:

class MyModel
  include Quartz::Verifiable

  property :phase : String?
  check :phase, presence: true
end

model = MyModel.new
model.phase = ""
model.invalid?          # => true
model.phase = "idle"
model.invalid?          # => false

Context can optionally be supplied to define which verifiers to test against (the context is defined on the verifiers using on: option).


[View source]
def valid?(context : Symbol? = nil) : Bool #

Runs all the specified verifications and returns true if no errors were added otherwise false.


[View source]