Module: TypedUUID

Defined in:
lib/typed_uuid.rb,
lib/typed_uuid/version.rb
more...

Defined Under Namespace

Modules: ActiveRecord, PsqlColumnMethods, PsqlSchemaDumper Classes: Railtie

Constant Summary collapse

VERSION =
'3.0'

Class Method Summary collapse

Class Method Details

.enum(uuid) ⇒ Object

[View source]

12
13
14
15
# File 'lib/typed_uuid.rb', line 12

def self.enum(uuid)
  uuid = uuid.gsub('-', '')
  (uuid[8..11].to_i(16) ^ uuid[16..19].to_i(16)) ^ uuid[12..15].to_i(16)
end

.uuid(enum) ⇒ Object

[View source]

6
7
8
9
10
# File 'lib/typed_uuid.rb', line 6

def self.uuid(enum)
  uuid = SecureRandom.random_bytes(16).unpack("NnnnnN")
  uuid[2] = (uuid[1] ^ uuid[3]) ^ enum
  "%08x-%04x-%04x-%04x-%04x%08x" % uuid
end