class

Assert::Assertions::NotBlank(PropertyType)

Inherits Assert::Assertions::Assertion / Reference / Object

Validates a property is not blank, that is, does not consist exclusively of unicode whitespace.

Optional Arguments

  • normalizer - Execute a Proc to alter actual before checking its validity.

Example

class Example
  include Assert

  def initialize; end

  @[Assert::NotBlank]
  property string : String = "foo"

  @[Assert::NotBlank]
  property single_character : String = "   a   "

  @[Assert::NotBlank]
  property nilble_string : String? = nil

  @[Assert::NotBlank(normalizer: ->(actual : String) { "Hello #{actual}" })]
  property normalizer : String = ""
end

Example.new.valid? # => true

Constructors

new(property_name : String, actual : Union(String, Nil), normalizer : Proc(String, String) | Nil = nil, message : String | Nil = nil, groups : Array(String) | Nil = nil)
Source

Instance methods

default_message_template

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

Source
message

The message to display if self is not valid.

NOTE: This method is defined automatically, and is just present for documentation purposes.

Source
valid?

Returns true if a property satisfies self, otherwise false.

Source