class Assert::Assertions::InRange(PropertyType, RangeType)
Overview
Validates a property is within a given Range
.
Optional Arguments
- not_in_range_message - Message to display if actual is not included in range.
- min_message - Message to display if range only has a minimum and actual is too small.
- max_message - Message to display if range only has a maximum and actual is too big.
Example
class Example
include Assert
def initialize; end
@[Assert::InRange(Range(Float64, Nil), range: 0.0..)]
property minimum_only : Int32 = 27
@[Assert::InRange(Range(Nil, Int64), range: ..100_000_000_000)]
property maximum_only : Int32 = 50_000
@[Assert::InRange(Range(Float64, Float64), range: 0.0..1000.0)]
property range : Float64 = 3.14
@[Assert::InRange(Range(Int32, Int32), range: 0..10, not_in_range_message: "That is not a valid %{property_name}")]
property fav_number : UInt8 = 8_u8
@[Assert::InRange(Range(UInt8, UInt8), range: 0_u8..50_u8, min_message: "Number of cores must be positive", max_message: "There must be less than 50 cores")]
property cores : Int32 = 32
end
Example.new.valid? # => true
NOTE The generic RangeType
represents the type of range.
Defined in:
assertions/in_range.crConstructors
Instance Method Summary
-
#default_message_template : String
Returns the default
#message_template
to use if no message is provided. -
#message : String
The message to display if
self
is not valid. -
#valid? : Bool
Returns
true
if a property satisfiesself
, otherwisefalse
.
Instance methods inherited from class Assert::Assertions::Assertion
default_message_template : String
default_message_template,
groups : Array(String)
groups,
message : String
message,
message_template : String
message_template,
property_name : String
property_name,
valid? : Bool
valid?
Constructor methods inherited from class Assert::Assertions::Assertion
new(property_name : String, message : String? = nil, groups : Array(String)? = nil)
new
Constructor Detail
def self.new(property_name : String, actual : PropertyType, range : RangeType, not_in_range_message : String? = nil, min_message : String? = nil, max_message : String? = nil, message : String? = nil, groups : Array(String)? = nil)
#
Instance Method Detail
def default_message_template : String
#
Returns the default #message_template
to use if no message is provided.
def message : String
#
The message to display if self
is not valid.
NOTE This method is defined automatically, and is just present for documentation purposes.
def valid? : Bool
#
Returns true
if a property satisfies self
, otherwise false
.
ameba:disable Metrics/CyclomaticComplexity