class Jennifer::Model::Errors
- Jennifer::Model::Errors
- Reference
- Object
Overview
Container that you can include in your object for handling error messages.
An example of a minimal implementation could be:
class Post
include Jennifer::Model::Translation
property title : String?
getter errors
def initialize
@errors = Jennifer::Model::Errors.new(self)
end
def validate
errors.add(:title, :blank) if title.nil?
end
# The following method is needed to be minimally implemented
def self.superclass; end
end
The last method in the described class is required to be implemented to allow Jennifer::Model::Errors to
correctly work with class translation lookup. nil
return value presents that class has no lookup.
Defined in:
jennifer/model/errors.crConstructors
Instance Method Summary
-
#[](attribute : Symbol)
When passed a symbol or a name of a method, returns an array of errors for the method.
- #[]?(attribute : Symbol)
-
#add(attribute : Symbol, message : String | Symbol = :invalid, count : Int? = nil, options : Hash = {} of String => String)
Adds
message
to the error messages and used validator type todetails
onattribute
. - #add(attribute : Symbol, message : String | Symbol = :invalid, options : Hash = {} of String => String)
- #any?
-
#blank?
Returns if object is blank one - empty (or whitespaced) string, empty array, empty hash,
nil
orfalse
. -
#clear
Clear the error messages.
-
#clone
Returns a copy of
self
with all instance variables cloned. -
#delete(key : Symbol)
Delete messages for
key
. -
#each(&)
Iterates through each error key, value pair in the error messages hash.
-
#empty?
Returns
true
if no errors are found,false
otherwise. -
#full_message(attribute : Symbol, message : String)
Returns a full message for a given attribute.
-
#full_messages
Returns all the full error messages in an array.
-
#full_messages_for(attribute : Symbol)
Returns all the full error messages for a given attribute in an array.
-
#generate_message(attribute : Symbol, message : Symbol, count, options : Hash)
Translates an error message in its default scope
- #generate_message(attribute : Symbol, message : String, count, options : Hash)
-
#include?(attribute : Symbol)
Returns whether error messages include an error for the given key
attribute
. - #inspect(io) : Nil
-
#keys
Returns all message keys.
-
#size
Returns the number of error messages.
- #to_a
-
#values
Returns all message values.
Constructor Detail
Instance Method Detail
When passed a symbol or a name of a method, returns an array of errors for the method.
Adds message
to the error messages and used validator type to details
on attribute
.
More than one error can be added to the same attribute
.
If no message
is supplied, :invalid
is assumed.
Returns if object is blank one - empty (or whitespaced) string, empty array, empty hash, nil
or false
.
Iterates through each error key, value pair in the error messages hash.
Yields the attribute and the error for that attribute. If the attribute has more than one error message, yields once for each error message.
Returns true
if no errors are found, false
otherwise.
If the error message is a string it can be empty.
Returns a full message for a given attribute.
Returns all the full error messages for a given attribute in an array.
Translates an error message in its default scope
Returns whether error messages include an error for the given key attribute
.