class Athena::Validator::Constraints::Range
inherits Athena::Validator::Constraint
#
Validates that a Number or Time value is between some minimum and maximum.
class House
include AVD::Validatable
def initialize(@area : Number); end
@[Assert::Range(15..100)]
property area : Number
end
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.
not_in_range_message#
Type: String Default: This value should be between {{ min }} and {{ max }}.
The message that will be shown if the value is less than the min or greater than the max.
Placeholders#
The following placeholders can be used in this message:
{{ value }}- The current (invalid) value.{{ min }}- The lower limit.{{ max }}- The upper limit.
min_message#
Type: String Default: This value should be {{ limit }} or more.
The message that will be shown if the value is less than the min, and no max has been provided.
Placeholders#
The following placeholders can be used in this message:
{{ value }}- The current (invalid) value.{{ limit }}- The lower limit.
max_message#
Type: String Default: This value should be {{ limit }} or less.
The message that will be shown if the value is more than the max, and no min has been provided.
Placeholders#
The following placeholders can be used in this message:
{{ value }}- The current (invalid) value.{{ limit }}- The upper limit.
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.
Constants#
NOT_IN_RANGE_ERROR = "7e62386d-30ae-4e7c-918f-1b7e571c6d69"#
TOO_HIGH_ERROR = "5d9aed01-ac49-4d8e-9c16-e4aab74ea774"#
TOO_LOW_ERROR = "f0316644-882e-4779-a404-ee7ac97ddecc"#
Constructors#
.new(range : ::Range, not_in_range_message : String = "This value should be between {{ min }} and {{ max }}.", min_message : String = "This value should be {{ limit }} or more.", max_message : String = "This value should be {{ limit }} or less.", groups : Array(String) | String | Nil = nil, payload : Hash(String, String) | Nil = nil)#
Methods#
#validated_by : AVD::ConstraintValidator.class#
Returns the AVD::ConstraintValidator.class that should handle validating self.