class Assert::Assertions::LessThanOrEqual(PropertyType)

Overview

Validates a property is less than or equal to value.

Example

class Example
  include Assert

  def initialize; end

  @[Assert::LessThanOrEqual(value: 100)]
  property int32_property : Int32 = 100

  @[Assert::LessThanOrEqual(value: 0.0001_f64)]
  property float_property : Float64 = 0.000001

  @[Assert::LessThanOrEqual(value: "X")]
  property string_property : String = "X"

  @[Assert::LessThanOrEqual(value: Time.utc(2019, 6, 1))]
  property start_date : Time? = Time.utc(2019, 5, 29)

  @[Assert::LessThanOrEqual(value: start_date)]
  property end_date : Time?

  @[Assert::LessThanOrEqual(value: max_value)]
  property getter_property : UInt8 = 250_u8

  def max_value : UInt8
    255_u8
  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.

NOTE PropertyType can be anything that defines a #<= method.

Defined in:

assertions/less_than_or_equal.cr

Constructors

Instance Method Summary

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, value : PropertyType, message : String? = nil, groups : Array(String)? = nil) #

[View source]

Instance Method Detail

def default_message_template : String #

Returns the default #message_template to use if no message is provided.


[View source]
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.


[View source]
def valid? : Bool #

Returns true if a property satisfies self, otherwise false.


[View source]