class Athena::Validator::Constraints::Valid

Overview

Tells the validator that it should also validate objects embedded as properties on an object being validated.

Configuration

Optional Arguments

NOTE This constraint does not support a message argument.

groups

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

The [validation groups][Athena::Validator::Constraint--validation-groups] this constraint belongs to. AVD::Constraint::DEFAULT_GROUP is assumed if nil.

payload

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

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

Usage

Without this constraint, objects embedded in another object are not valided.

class SubObjectOne
  include AVD::Validatable

  @[Assert::NotBlank]
  getter string : String = ""
end

class SubObjectTwo
  include AVD::Validatable

  @[Assert::NotBlank]
  getter string : String = ""
end

class MyObject
  include AVD::Validatable

  # This object is not validated when validating `MyObject`.
  getter sub_object_one : SubObjectOne = SubObjectOne.new

  # Have the validator also validate `SubObjectTwo` when validating `MyObject`.
  @[Assert::Valid]
  getter sub_object_two : SubObjectTwo = SubObjectTwo.new
end

Defined in:

constraints/valid.cr

Constructors

Instance Method Summary

Instance methods inherited from class Athena::Validator::Constraint

add_implicit_group(group : String) : Nil add_implicit_group, groups : Array(String) groups, groups=(groups : Array(String)) groups=, message : String message, payload : Hash(String, String) | Nil payload, validated_by : AVD::ConstraintValidator.class validated_by

Constructor methods inherited from class Athena::Validator::Constraint

new(message : String, groups : Array(String) | String | Nil = nil, payload : Hash(String, String) | Nil = nil) new

Class methods inherited from class Athena::Validator::Constraint

error_name(error_code : String) : String error_name

Constructor Detail

def self.new(traverse : Bool = true, groups : Array(String) | String | Nil = nil, payload : Hash(String, String) | Nil = nil) #

[View source]

Instance Method Detail

def traverse? : Bool #

[View source]
def validated_by : AVD::ConstraintValidator.class #

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


[View source]