module Athena::Validator::ExecutionContextInterface
Overview
Stores contextual data related to the current validation run.
This includes the violations generated so far, the current constraint, value being validated, etc.
Adding Violations
As mentioned in the AVD::ConstraintValidatorInterface
documentation,
violations are not returned from the AVD::ConstraintValidatorInterface#validate
method.
Instead they are added to the AVD::ConstraintValidatorInterface#context
instance.
The simplest way to do so is via the #add_violation
method, which accepts the violation message,
and any parameters that should be used to render the message.
Additional overloads exist to make adding a value with a specific message, and code, or message, code, and {{ value }}
placeholder value easier.
Building violations
In some cases you may wish to add additional data to the AVD::Violation::ConstraintViolationInterface
before adding it to self
.
To do this, you can also use the #build_violation
method, which returns an AVD::Violation::ConstraintViolationBuilderInterface
that can be used to construct a violation, with an easier API.
Direct including types
Defined in:
execution_context_interface.crInstance Method Summary
-
#add_violation(message : String, code : String, value : _) : Nil
Adds a violation with the provided message, and code, value parameter.
-
#add_violation(message : String, parameters : Hash(String, String) = {} of String => String) : Nil
Adds a violation with the provided message, and optionally parameters based on the node currently being validated.
-
#add_violation(message : String, code : String) : Nil
Adds a violation with the provided message and code
-
#build_violation(message : String, code : String, value : _) : AVD::Violation::ConstraintViolationBuilderInterface
Returns an
AVD::Violation::ConstraintViolationBuilderInterface
with the provided message, and code, and value. -
#build_violation(message : String, parameters : Hash(String, String) = {} of String => String) : AVD::Violation::ConstraintViolationBuilderInterface
Returns an
AVD::Violation::ConstraintViolationBuilderInterface
with the provided message. -
#build_violation(message : String, code : String) : AVD::Violation::ConstraintViolationBuilderInterface
Returns an
AVD::Violation::ConstraintViolationBuilderInterface
with the provided message, and code. -
#class_name
Returns the class that is currently being validated.
-
#constraint : AVD::Constraint | Nil
Returns the
AVD::Constraint
that is currently being validated, if any. -
#group : String | Nil
Returns the group that is currently being validated, if any.
-
#metadata : AVD::Metadata::MetadataInterface | Nil
Returns an
AVD::Metadata::MetadataInterface
object for the value currently being validated. -
#object
Returns the object that is currently being validated.
-
#property_name : String | Nil
Returns the property name of the node currently being validated.
-
#property_path : String
Returns the path to the property that is currently being validated.
-
#root
Returns the object initially passed to
AVD::Validator::ValidatorInterface#validate
. -
#validator : AVD::Validator::ValidatorInterface
Returns a reference to an
AVD::Validator::ValidatorInterface
that can be used to validate additional constraints as part of another constraint. -
#value
Returns the value that is currently being validated.
-
#violations : AVD::Violation::ConstraintViolationListInterface
Returns the
AVD::Violation::ConstraintViolationInterface
instances generated by the validator thus far.
Instance Method Detail
Adds a violation with the provided message, and code, value parameter.
The provided value is added to the violations' parameters as "{{ value }}"
.
Adds a violation with the provided message, and optionally parameters based on the node currently being validated.
Adds a violation with the provided message and code
Returns an AVD::Violation::ConstraintViolationBuilderInterface
with the provided message, and code, and value.
The provided value is added to the violations' parameters as "{{ value }}"
.
Returns an AVD::Violation::ConstraintViolationBuilderInterface
with the provided message.
Can be used to add additional information to the AVD::Violation::ConstraintViolationInterface
being adding it to self
.
Returns an AVD::Violation::ConstraintViolationBuilderInterface
with the provided message, and code.
Returns the AVD::Constraint
that is currently being validated, if any.
Returns an AVD::Metadata::MetadataInterface
object for the value currently being validated.
This would be an AVD::Metadata::PropertyMetadataInterface
if the current value is an object,
an AVD::Metadata::GenericMetadata
if the current value is a plain value, and an
AVD::Metadata::ClassMetadata
if the current value value is an entire class.
Returns the property name of the node currently being validated.
Returns the path to the property that is currently being validated.
For example, given a Person
object that has an Address
property;
the property path would be empty initially. When the address
property
is being validated the property_path would be address
.
When the street property of the related Address
object is being validated
the property_path would be address.street
.
This also works for collections of objects. If the Person
object had multiple
addresses, the property path when validating the first street of the first address
would be addresses[0].street
.
Returns the object initially passed to AVD::Validator::ValidatorInterface#validate
.
Returns a reference to an AVD::Validator::ValidatorInterface
that can be used to validate
additional constraints as part of another constraint.
Returns the AVD::Violation::ConstraintViolationInterface
instances generated by the validator thus far.