Class: Hexx::Entities::UUID

Inherits:
String
  • Object
show all
Includes:
Attestor::Validations
Defined in:
lib/hexx-entities/uuid.rb

Overview

Class UUID provides validatable value object that describes UUID

Examples:

Creates a string

uuid = UUID.new "12345678-90ab-cdef-1234-567890abcdef"
# => "12345678-90ab-cdef-1234-567890abcdef"

Validates the format of its own

uuid = UUID.new "wrong format"
uuid.validate.valid? # => false

Generates a default value for nil

uuid = UUID.new nil
# => "97f340af-8157-5c3a-1571-743d208da957"

See Also:

Author:

Constant Summary collapse

FORMAT =
/^\h{8}(-\h{4}){3}-\h{12}$/

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ UUID

Returns a new instance of UUID.



32
33
34
# File 'lib/hexx-entities/uuid.rb', line 32

def initialize(value)
  super (value || SecureRandom.uuid).to_s
end