class Athena::Validator::Constraints::Size

Overview

Validates that the #size of a String or Indexable value is between some minimum and maximum.

Configuration

Required Arguments

range

Type: ::Range

The ::Range that defines the minimum and maximum values, if any. An endless range can be used to only have a minimum or maximum.

Optional Arguments

NOTE This constraint does not support a message argument.

exact_message

Type: String Default: This value should have exactly {{ limit }} {{ type }}.|This value should have exactly {{ limit }} {{ type }}s.

The message that will be shown if min and max values are equal and the underlying value’s size is not exactly this value. The message is pluralized depending on how many elements/characters the underlying value has.

Placeholders

The following placeholders can be used in this message:

min_message

Type: String Default: This value is too short. It should have {{ limit }} {{ type }} or more.|This value is too short. It should have {{ limit }} {{ type }}s or more.

The message that will be shown if the underlying value’s size is less than the min. The message is pluralized depending on how many elements/characters the underlying value has.

Placeholders

The following placeholders can be used in this message:

max_message

Type: String Default: This value is too long. It should have {{ limit }} {{ type }} or less.|This value is too long. It should have {{ limit }} {{ type }}s or less.

The message that will be shown if the underlying value’s size is greater than the max. The message is pluralized depending on how many elements/characters the underlying value has.

Placeholders

The following placeholders can be used in this message:

groups

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

The 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 is not used by Athena::Validator, but its processing is completely up to you.

Defined in:

constraints/size.cr

Constant Summary

TOO_LONG_ERROR = "a1fa7a63-ea3b-46a0-adcc-5e1bcc26f73a"
TOO_SHORT_ERROR = "8ba31c71-1b37-4b76-8bc9-66896589b01f"

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)? 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) new

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

error_name(error_code : String) : String error_name

Constructor Detail

def self.new(range : ::Range, min_message : String = "This value is too short. It should have {{ limit }} {{ type }} or more.|This value is too short. It should have {{ limit }} {{ type }}s or more.", max_message : String = "This value is too long. It should have {{ limit }} {{ type }} or less.|This value is too long. It should have {{ limit }} {{ type }}s or less.", exact_message : String = "This value should have exactly {{ limit }} {{ type }}.|This value should have exactly {{ limit }} {{ type }}s.", groups : Array(String) | String | Nil = nil, payload : Hash(String, String)? = nil) #

[View source]

Instance Method Detail

def exact_message : String #

[View source]
def max : Int32? #

[View source]
def max_message : String #

[View source]
def min : Int32? #

[View source]
def min_message : String #

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

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


[View source]