class Athena::Validator::Constraints::Range

Overview

Validates that a Number or Time 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.

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:

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:

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:

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/range.cr

Constant Summary

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

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(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) #

[View source]

Instance Method Detail

def max : Number::Primitive | Time | Nil #

[View source]
def max_message : String #

[View source]
def min : Number::Primitive | Time | Nil #

[View source]
def min_message : String #

[View source]
def not_in_range_message : String #

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

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


[View source]