class Marten::Core::Validation::ErrorSet

Overview

Represents a set of validation errors.

Included Modules

Defined in:

marten/core/validation/error_set.cr
marten/template/ext/core/validation/error_set.cr

Constant Summary

DEFAULT_ERROR_TYPE = :invalid

Constructors

Instance Method Summary

Macros inherited from module Marten::Template::Object

template_attributes(*names) template_attributes

Constructor Detail

def self.new #

[View source]

Instance Method Detail

def [](field : Nil | String | Symbol) #

Returns all the errors associated with a specific field.


[View source]
def add(field : String | Symbol, message : String, *, type : Nil | String | Symbol = nil) #

Adds a new field error to the error set.

This method can be used to add a new error associated with a specific field to an existing error set. At least a field and a message must be specified:

record.errors.add(:attribute, "This record attribute is invalid")

Optionnaly, an error type can be explicitely specified, otherwise it defaults to :invalid:

records.errors.add(:attribute, "This record attribute is invalid!", type: :invalid_attribute)

[View source]
def add(message : String, *, type : Nil | String | Symbol = nil) #

Adds a new global error to the error set.

This method can be used to add a new global error (that is not associated with a specific field) to an existing error set. At least a message must be specified:

record.errors.add("This record is invalid!")

Optionnaly, an error type can be explicitely specified, otherwise it defaults to :invalid:

record.errors.add("This record is invalid!", type: :invalid_record)

[View source]
def clear(*args, **options) #

Clears all the Marten::Core::Validation::Error objects from this error set.


[View source]
def clear(*args, **options, &) #

Clears all the Marten::Core::Validation::Error objects from this error set.


[View source]
def each(*args, **options) #

Iterates over all the Marten::Core::Validation::Error objects in this error set.


[View source]
def each(*args, **options, &) #

Iterates over all the Marten::Core::Validation::Error objects in this error set.


[View source]
def global #

Returns the global errors (errors that are not associated with a specific field).


[View source]
def size(*args, **options) #

Returns the number of errors.


[View source]
def size(*args, **options, &) #

Returns the number of errors.


[View source]