Sha256: 7c3cd2bf01c11eba729ee59a9e7478771365254a10b929c7c21233b9c3976466

Contents?: true

Size: 1.18 KB

Versions: 7

Compression:

Stored size: 1.18 KB

Contents

module RDF; module Util
  ##
  # Utilities for UUID handling.
  #
  # @see http://en.wikipedia.org/wiki/Universally_unique_identifier
  module UUID
    ##
    # 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]:      http://rubygems.org/gems/uuid
    # [UUIDTools]: http://rubygems.org/gems/uuidtools
    #
    # @param  [:default, :compact, :urn] format (:default)
    # @param  [Hash{Symbol => Object}] options
    #   any options to pass through to the underlying UUID library
    # @return [String] a UUID string
    # @raise  [LoadError] if no UUID library is available
    # @see    http://rubygems.org/gems/uuid
    # @see    http://rubygems.org/gems/uuidtools
    def self.generate(format: :default, **options)
      begin
        require 'uuid'
        ::UUID.generate(format)
      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
  end # UUID
end; end # RDF::Util

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rdf-2.2.6 lib/rdf/util/uuid.rb
rdf-2.2.5 lib/rdf/util/uuid.rb
rdf-2.2.4 lib/rdf/util/uuid.rb
rdf-2.2.3 lib/rdf/util/uuid.rb
rdf-2.2.1 lib/rdf/util/uuid.rb
rdf-2.2.0 lib/rdf/util/uuid.rb
rdf-2.2.0.pre.rc1 lib/rdf/util/uuid.rb