class Assert::Assertions::Uuid(PropertyType)

Overview

Validates a string is a properly formatted RFC4122 UUID; either in hyphenated, hexstring, or urn formats.

Optional Arguments

Example

class Example
  include Assert

  def initialize; end

  @[Assert::Uuid(strict: false)]
  property hyphenless : String = "216fff4098d911e3a5e20800200c9a66"

  @[Assert::Uuid(strict: false)]
  property urn : String = "urn:uuid:3f9eaf9e-cdb0-45cc-8ecb-0e5b2bfb0c20"

  @[Assert::Uuid]
  property strict : String = "216fff40-98d9-11e3-a5e2-0800200c9a66"

  @[Assert::Uuid(versions: [UUID::Version::V1])]
  property v1_only : String = "216fff40-98d9-11e3-a5e2-0800200c9a66"

  @[Assert::Uuid(variants: [UUID::Variant::Future, UUID::Variant::NCS])]
  property other_variants : String = "216fff40-98d9-11e3-e5e2-0800200c9a66"

  @[Assert::Uuid(normalizer: ->(actual : String) { actual.strip })]
  property normalizer : String = "    216fff40-98d9-11e3-a5e2-0800200c9a66    "
end

Example.new.valid? # => true

Defined in:

assertions/uuid.cr

Constant Summary

HYPHEN_INDEXES = {8, 13, 18, 23}

The indxes where a strict UUID should have a hyphen.

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 : Union(String, Nil), versions : Array(UUID::Version) = [UUID::Version::V1, UUID::Version::V2, UUID::Version::V3, UUID::Version::V4, UUID::Version::V5], variants : Array(UUID::Variant) = [UUID::Variant::RFC4122], strict : Bool = true, normalizer : Proc(String, String)? = nil, 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]