Class: Stannum::Constraints::Uuid

Inherits:
Format show all
Defined in:
lib/stannum/constraints/uuid.rb

Overview

A UUID constraint asserts the value is a string in UUID format.

Examples:

Using a UUID constraint with a String format.

constraint = Stannum::Constraints::Uuid.new

constraint.matches?(nil)                                    #=> false
constraint.matches?('Hello, world')                         #=> false
constraint.matches?('01234567-89ab-cdef-0123-456789abcdef') #=> true

Constant Summary collapse

NEGATED_TYPE =

The :type of the error generated for a matching object.

'stannum.constraints.is_a_uuid'
TYPE =

The :type of the error generated for a non-matching object.

'stannum.constraints.is_not_a_uuid'
UUID_FORMAT =

Regular expression describing a valid upper- or lower-case UUID.

/\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/

Instance Attribute Summary

Attributes inherited from Format

#expected_format

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Format

#errors_for, #matches?

Methods inherited from Base

#==, #clone, #does_not_match?, #dup, #errors_for, #match, #matches?, #message, #negated_errors_for, #negated_match, #negated_message, #negated_type, #type, #with_options

Constructor Details

#initialize(**options) ⇒ Uuid

Returns a new instance of Uuid.

Parameters:

  • options (Hash<Symbol, Object>)

    Configuration options for the constraint. Defaults to an empty Hash.



26
27
28
# File 'lib/stannum/constraints/uuid.rb', line 26

def initialize(**options)
  super(UUID_FORMAT, **options)
end