Sha256: 3744d8c15c7f999d82164ddbd008530645995f982f72e7f5b78c853ac3df13ff

Contents?: true

Size: 636 Bytes

Versions: 11

Compression:

Stored size: 636 Bytes

Contents

module Skylight
  module Util
    class UUID
      BYTE_SIZE   = 16
      PREFIX_SIZE = 8

      def self.gen(prefix = nil)
        if prefix == nil
          return SecureRandom.random_bytes(BYTE_SIZE)
        end

        if prefix.bytesize > PREFIX_SIZE
          raise "UUID prefix must be less than 8 bytes"
        end

        # Does not fully conform with the spec
        rnd = SecureRandom.random_bytes(BYTE_SIZE - prefix.bytesize)
        new "#{prefix}#{rnd}"
      end

      attr_reader :bytes

      def initialize(bytes)
        @bytes = bytes
      end

      def to_s
        @to_s ||= ""
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
skylight-0.0.16 lib/skylight/util/uuid.rb
skylight-0.0.15 lib/skylight/util/uuid.rb
skylight-0.0.14 lib/skylight/util/uuid.rb
skylight-0.0.13 lib/skylight/util/uuid.rb
skylight-0.0.12 lib/skylight/util/uuid.rb
skylight-0.0.11 lib/skylight/util/uuid.rb
skylight-0.0.10 lib/skylight/util/uuid.rb
skylight-0.0.7 lib/skylight/util/uuid.rb
skylight-0.0.6 lib/skylight/util/uuid.rb
skylight-0.0.5 lib/skylight/util/uuid.rb
skylight-0.0.2 lib/skylight/util/uuid.rb