Module: RDF::Util::UUID

Defined in:
lib/rdf/util/uuid.rb

Overview

Utilities for UUID handling.

Class Method Summary collapse

Class Method Details

.generate(options = {}) ⇒ String

Generates a UUID string.

This will make use of either the [UUID][] gem or the [UUIDTools][] gem, whichever of the two happens to be available.

[UUID]: rubygems.org/gems/uuid [UUIDTools]: rubygems.org/gems/uuidtools

Parameters:

  • options (Hash{Symbol => Object}) (defaults to: {})

    any options to pass through to the underlying UUID library

Returns:

  • (String)

    a UUID string

Raises:

  • (LoadError)

    if no UUID library is available

See Also:



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rdf/util/uuid.rb', line 22

def self.generate(options = {})
  begin
    require 'uuid'
    ::UUID.generate(options[:format] || :default)
  rescue LoadError => e
    begin
      require 'uuidtools'
      ::UUIDTools::UUID.random_create.hexdigest
    rescue LoadError => e
      raise LoadError.new("no such file to load -- uuid or uuidtools")
    end
  end
end