struct Athena::Validator::Constraints::GroupSequence

Overview

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.

Defined in:

constraints/group_sequence.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(groups : Array(String)) #

[View source]
def self.new(groups : Array(String | Array(String))) #

[View source]

Instance Method Detail

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

[View source]