module Granite::Validators

Overview

Analyze validation blocks and procs

By example:

validate :name, "can't be blank" do |user|
  !user.name.to_s.blank?
end

validate :name, "can't be blank", ->(user : User) do
  !user.name.to_s.blank?
end

name_required = ->(model : Granite::Base) { !model.name.to_s.blank? }
validate :name, "can't be blank", name_required

Direct including types

Defined in:

granite/validators.cr

Instance Method Summary

Instance Method Detail

def errors #

Returns all errors on the model.


[View source]
def valid? #

Runs all of self's validators, returning true if they all pass, and false otherwise.

If the validation fails, #errors will contain all the errors responsible for the failing.


[View source]