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:
{{ value }}
- The current (invalid) value.{{ limit }}
- The exact expected size.{{ type }}
-character
if the value is a string oritem
if the value is an indexable.
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:
{{ value }}
- The current (invalid) value.{{ limit }}
- The expected minimum size.{{ type }}
-character
if the value is a string oritem
if the value is an indexable.
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:
{{ value }}
- The current (invalid) value.{{ limit }}
- The expected minimum size.{{ type }}
-character
if the value is a string oritem
if the value is an indexable.
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.
Defined in:
constraints/size.crConstant Summary
-
TOO_LONG_ERROR =
"a1fa7a63-ea3b-46a0-adcc-5e1bcc26f73a"
-
TOO_SHORT_ERROR =
"8ba31c71-1b37-4b76-8bc9-66896589b01f"
Constructors
Instance Method Summary
- #exact_message : String
- #max : Int32 | Nil
- #max_message : String
- #min : Int32 | Nil
- #min_message : String
-
#validated_by : AVD::ConstraintValidator.class
Returns the
AVD::ConstraintValidator.class
that should handle validatingself
.
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
Instance Method Detail
Returns the AVD::ConstraintValidator.class
that should handle validating self
.