abstract struct Athena::Validator::ConstraintValidator

Overview

Basic implementation of AVD::ConstraintValidatorInterface.

Included Modules

Direct Known Subclasses

Defined in:

constraint_validator.cr

Constructors

Instance Method Summary

Instance methods inherited from module Athena::Validator::ConstraintValidatorInterface

context : AVD::ExecutionContextInterface context, validate(value : _, constraint : AVD::Constraint) : Nil validate

Constructor Detail

def self.new #

[View source]

Instance Method Detail

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

See the type for more information.


[View source]
def initialize #

[View source]
def 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]
def validate(value : _, constraint : AVD::Constraint) : Nil #

Validate the provided value against the provided constraint.

Violations should be added to the current #context.


[View source]