Class: Fog::UUID

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/core/uuid.rb

Class Method Summary collapse

Class Method Details

.supported?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/fog/core/uuid.rb', line 18

def supported?
  SecureRandom.respond_to?(:uuid)
end

.uuidObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/core/uuid.rb', line 7

def uuid
  if supported?
    SecureRandom.uuid
  else
    ary = SecureRandom.random_bytes(16).unpack("NnnnnN")
    ary[2] = (ary[2] & 0x0fff) | 0x4000
    ary[3] = (ary[3] & 0x3fff) | 0x8000
    "%08x-%04x-%04x-%04x-%04x%08x" % ary
  end
end