mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[core] removing uuidtools dependency; added Fog::UUID class
This commit is contained in:
parent
aae2a4f7d9
commit
773104e9dc
4 changed files with 38 additions and 1 deletions
|
@ -51,7 +51,6 @@ Gem::Specification.new do |s|
|
|||
s.add_dependency('nokogiri', '~>1.5')
|
||||
s.add_dependency('ruby-hmac')
|
||||
s.add_dependency('unicode', "~> 0.4.4")
|
||||
s.add_dependency('uuidtools', ">= 2.1.0")
|
||||
|
||||
## List your development dependencies here. Development dependencies are
|
||||
## those that are only needed during development
|
||||
|
|
|
@ -31,6 +31,7 @@ require 'fog/core/time'
|
|||
require 'fog/core/timeout'
|
||||
require 'fog/core/wait_for'
|
||||
require 'fog/core/class_from_string'
|
||||
require 'fog/core/uuid'
|
||||
|
||||
# data exchange specific (to be extracted and used on a per provider basis)
|
||||
require 'fog/xml'
|
||||
|
|
21
lib/fog/core/uuid.rb
Normal file
21
lib/fog/core/uuid.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
require 'securerandom'
|
||||
|
||||
module Fog
|
||||
class UUID
|
||||
class << self
|
||||
|
||||
def uuid
|
||||
if supported?
|
||||
SecureRandom.uuid
|
||||
else
|
||||
raise "UUID generation is not supported by your ruby implementation. Please try upgrading to Ruby 1.9.x."
|
||||
end
|
||||
end
|
||||
|
||||
def supported?
|
||||
SecureRandom.respond_to?(:uuid)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
16
tests/core/uuid_tests.rb
Normal file
16
tests/core/uuid_tests.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
Shindo.tests('Fog::UUID', 'core') do
|
||||
|
||||
tests('supported?').succeeds 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
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue