Class: UUID
- Inherits:
-
Object
- Object
- UUID
- Defined in:
- lib/toolbox/uuid.rb
Overview
A generic UUID class
== Usage
$ irb
require 'toolbox/uuid'
=> true
UUID.generate
=> "0a391631-22ba-40ea-af2e-65a64de4a42b"
UUID.generate
=> "092516ba-a2f4-45cf-9e1d-c5e63342aaa4"
Class Method Summary collapse
-
.generate ⇒ Object
Generate a random UUID.
Class Method Details
.generate ⇒ Object
Generate a random UUID.
Attempts a few different ways, hopefully one of them work. If all fails, die.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/toolbox/uuid.rb', line 21 def self.generate begin require 'securerandom' return SecureRandom.uuid() rescue Exception => e if (File.exist?("/usr/bin/uuidgen")) # Centos e2fsprogs package uuid = `/usr/bin/uuidgen` return uuid.chomp elsif (File.exist?("/usr/bin/uuid")) # Debian uuid package uuid = `/usr/bin/uuid` return uuid.chomp end end abort("Unable to generate UUIDs") end |