class Assert::Assertions::Uuid(PropertyType)
Overview
Validates a string is a properly formatted RFC4122 UUID; either in hyphenated, hexstring, or urn formats.
Optional Arguments
- versions - Only allow specific UUID versions.
- variants - Only allow specific UUID variants.
- strict - Only allow the hyphenated UUID format.
- normalizer - Execute a
Proc
to alter actual before checking its validity.
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.crConstant Summary
-
HYPHEN_INDEXES =
{8, 13, 18, 23}
-
The indxes where a strict
UUID
should have a hyphen.
Constructors
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 = nil, groups : Array(String) | Nil = 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 = nil, message : String | Nil = nil, groups : Array(String) | Nil = 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.