Skip to content

abstract struct Athena::Validator::ConstraintValidator
inherits Struct #

Basic implementation of AVD::ConstraintValidatorInterface.

Included modules

Athena::Validator::ConstraintValidatorInterface

Direct known subclasses

Athena::Validator::Constraints::All::Validator Athena::Validator::Constraints::AtLeastOneOf::Validator Athena::Validator::Constraints::Blank::Validator Athena::Validator::Constraints::Callback::Validator Athena::Validator::Constraints::Choice::Validator Athena::Validator::Constraints::ComparisonValidator Athena::Validator::Constraints::Compound::Validator Athena::Validator::Constraints::Email::Validator Athena::Validator::Constraints::IP::Validator Athena::Validator::Constraints::ISBN::Validator Athena::Validator::Constraints::IsFalse::Validator Athena::Validator::Constraints::ISIN::Validator Athena::Validator::Constraints::IsNil::Validator Athena::Validator::Constraints::ISSN::Validator Athena::Validator::Constraints::IsTrue::Validator Athena::Validator::Constraints::Luhn::Validator Athena::Validator::Constraints::NotBlank::Validator Athena::Validator::Constraints::NotNil::Validator Athena::Validator::Constraints::Range::Validator Athena::Validator::Constraints::Regex::Validator Athena::Validator::Constraints::Sequentially::Validator Athena::Validator::Constraints::Size::Validator Athena::Validator::Constraints::Unique::Validator Athena::Validator::Constraints::URL::Validator Athena::Validator::Constraints::Valid::Validator Athena::Validator::ServiceConstraintValidator Athena::Validator::Spec::FailingConstraint::Validator

Class methods#

.new #

View source

Methods#

#context : AVD::ExecutionContextInterface #

Returns the a reference to the AVD::ExecutionContextInterface to which violations within self should be added.

See the type for more information.

View source

#raise_invalid_type(value : _, supported_types : String) : NoReturn #

Can be used to raise an AVD::Exceptions::UnexpectedValueError in case self is only able to validate values of the supported_types.

# Define a validate method to catch values of other types.
# Overloads above would handle the valid types.
def validate(value : _, constraint : AVD::Constraints::MyConstraint) : Nil
  self.raise_invalid_type value, "Int | Float"
end

This would result in a violation with the message This value should be a valid: Int | Float being added to the current #context.

View source

#validate(value : _, constraint : AVD::Constraint) : Nil #

Validate the provided value against the provided constraint.

Violations should be added to the current #context.

View source