module Check::Checkable
Overview
Mixin that adds #check
method to be used with variables of an instance of the class including it.
The idea is to check the instance variables of the class extending it
against rules defined with Check.rules
plus executing custom checkers defined with Checker
.
Defined in:
checkable.crInstance Method Summary
-
#after_check(v : Check::Validation, required : Bool = true, format : Bool = true)
Lifecycle method triggered after each call of
#check
. -
#before_check(v : Check::Validation, required : Bool = true, format : Bool = true)
Lifecycle method triggered before each call of
#check
. -
#check(required : Bool = true, format : Bool = true) : Validation
Same as
#check
but this method raises aCheck::ValidationError
if the validation fails or if the clean has not been processed successfully. -
#check(v : Check::Validation, required : Bool = true, format : Bool = true) : Validation
Checks the instance fields and clean them.
-
#check!(required : Bool = true, format : Bool = true) : self
Same as
#check
but this method raises aCheck::ValidationError
if the validation fails or if the clean has not been processed successfully. -
#check!(v : Check::Validation, required : Bool = true, format : Bool = true) : self
Same as
#check
but this method raises aCheck::ValidationError
if the validation fails or if the clean has not been processed successfully.
Instance Method Detail
Lifecycle method triggered after each call of #check
.
# Triggered on instance: `user.check`
def after_check(v : Check::Validation, required : Bool = true, format : Bool = true)
# Code...
end
Lifecycle method triggered before each call of #check
.
# Triggered on instance: `user.check`
def before_check(v : Check::Validation, required : Bool = true, format : Bool = true)
# Code...
end
Same as #check
but this method raises a Check::ValidationError
if the validation fails or if the clean has not been processed successfully.
myCheckable.check! # => Returns the current instance.
This method returns self
, so it chainable :)
user.email = "[email protected]"
user.check!.save
Checks the instance fields and clean them.
It instantiates a Check::Validation
(if not provided) and calls all methods
related to rules and then methods defined with annotation Checker
.
Lifecycle methods #before_check
and #after_check
that are triggered
respectively at the beginning and at the end of the process.
format is used to tell cleaners generated by Check.rules
to execute format method if it has been defined.
Same as #check
but this method raises a Check::ValidationError
if the validation fails or if the clean has not been processed successfully.
myCheckable.check! # => Returns the current instance.
This method returns self
, so it chainable :)
user.email = "[email protected]"
user.check!.save
Same as #check
but this method raises a Check::ValidationError
if the validation fails or if the clean has not been processed successfully.
v = Validation.new_validation
myCheckable.check!(v) # => Returns the current instance.
This method returns self
, so it chainable :)
v = Validation.new_validation
user.email = "[email protected]"
user.check!(v).save