Skip to content

abstract class Athena::Validator::Constraints::Compound
inherits Athena::Validator::Constraints::Composite #

Allows creating a custom set of reusable constraints, representing rules to use consistently across your application.

NOTE: See AVD::Constraint@custom-constraints for common documentation on defining custom constraints.


Optional Arguments#

NOTE: This constraint does not support a message argument.


Type: Array(String) | String | Nil Default: nil

The validation groups this constraint belongs to. AVD::Constraint::DEFAULT_GROUP is assumed if nil.


Type: Hash(String, String)? Default: nil

Any arbitrary domain-specific data that should be stored with this constraint. The payload is not used by Athena::Validator, but its processing is completely up to you.


This constraint is not used directly on its own; instead it's used to create another constraint.

# Define a compound constraint to centralize the logic to validate a password.
# NOTE: The constraint _MUST_ be defined within the `AVD::Constraints` namespace for implementation reasons.  This may change in the future.
class AVD::Constraints::ValidPassword < AVD::Constraints::Compound
  # Define a method that returns an array of the constraints we want to be a part of `self`.
  def constraints : Array(AVD::Constraint)
    [,       # Not empty/null,     # At least 12 characters longs^\d.*/), # Must start with a number

We can then use this constraint as we would any other.

Either as an annotation

getter password : String
or directly.

constraint =

Class methods#

.new(groups : Array(String) | String | Nil = nil, payload : Hash(String, String)? = nil) #

View source


abstract #constraints : Array(AVD::Constraint) #

View source

#validated_by : AVD::ConstraintValidator.class #

Returns the AVD::ConstraintValidator.class that should handle validating self.

View source