Skip to content

struct Athena::Validator::Constraints::GroupSequence
inherits Struct #

Allows validating your AVD::Constraint@validation-groups in steps. I.e. only continue to the next group if all constraints in the first group are valid.

@[Assert::GroupSequence("User", "strict")]
class User
  include AVD::Validatable

  @[Assert::NotBlank]
  property name : String

  @[Assert::NotBlank]
  property password : String

  def initialize(@name : String, @password : String); end

  @[Assert::IsTrue(message: "Your password cannot be the same as your name.", groups: "strict")]
  def is_safe_password? : Bool
    @name != @password
  end
end

In this case, it'll validate the name and password properties are not blank before validating they are not the same. If either property is blank, the is_safe_password? validation will be skipped.

Note

The default group is not allowed as part of a group sequence.

Note

Calling validate with a group in the sequence, such as strict, will cause violations to ONLY use that group and not all groups within the sequence. This is because the group sequence is now referred to as the default group.

See AVD::Constraints::GroupSequence::Provider for a way to dynamically determine the sequence an object should use.

Constructors#

.new(groups : Array(String))#

View source

.new(groups : Array(String | Array(String)))#

View source

Methods#

#groups : Array(String | Array(String))#

View source