1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[core] updated UUID to use it's own UUID implementation if one was not available from the ruby lib.

This commit is contained in:
Kyle Rames 2013-10-11 07:51:23 -05:00
parent e13306541f
commit bda470486a
2 changed files with 6 additions and 10 deletions

View file

@ -8,14 +8,16 @@ module Fog
if supported?
SecureRandom.uuid
else
raise "UUID generation is not supported by your ruby implementation. Please try upgrading to Ruby 1.9.x."
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
def supported?
SecureRandom.respond_to?(:uuid)
end
end
end
end

View file

@ -4,13 +4,7 @@ Shindo.tests('Fog::UUID', 'core') do
Fog::UUID.supported? == SecureRandom.respond_to?(:uuid)
end
if Fog::UUID.supported?
tests('success').succeeds do
Fog::UUID.uuid =~ /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
end
else
tests('success').succeeds do
raises(RuntimeError) { Fog::UUID.uuid }
end
tests('success').succeeds do
Fog::UUID.uuid =~ /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
end
end