Assert::Assertions::DivisibleBy(PropertyType)
Inherits Assert::Assertions::Assertion / Reference / Object
Validates a property is divisible by value.
Example
class Example
include Assert
def initialize; end
@[Assert::DivisibleBy(value: 0.5)]
property float : Float64 = 100.0
@[Assert::DivisibleBy(value: 2)]
property int : Int32 = 1234
@[Assert::DivisibleBy(value: get_value)]
property getter_property : UInt16 = 256_u16
def get_value : UInt16
16_u16
end
end
Example.new.valid? # => true
NOTE: value can be a hard-coded value like 10, the name of another property, a constant, or the name of a method.
NOTE: The type of value and the property must match.
Constructors
new(property_name : String, actual : PropertyType, value : PropertyType, message : String | Nil = nil, groups : Array(String) | Nil = nil)
SourceInstance methods
default_message_template
Returns the default #message_template to use if no message is provided.
message
The message to display if self is not valid.
NOTE: This method is defined automatically, and is just present for documentation purposes.