Module: NdrError::UuidBuilder

Included in:
Log
Defined in:
lib/ndr_error/uuid_builder.rb

Overview

Mixin to assist with building of UUIDs.

Instance Method Summary collapse

Instance Method Details

#construct_uuidObject

Populate the primary key column. Taking inspiration from MongoDB, hashes time, machine identifier etc so can be used for ordering at a pinch.



7
8
9
10
11
12
13
14
15
16
# File 'lib/ndr_error/uuid_builder.rb', line 7

def construct_uuid
  parts = [
    [Time.current.to_i].pack('N'),                # 4 bytes of current time seconds
    Digest::MD5.digest(Socket.gethostname)[0, 7], # 7 bytes of machine identifier
    [Process.pid % 0xFFFF].pack('n'),             # 2 bytes of pid (looping at 2^16)
    [increment_value].pack('N')[1, 3]             # 3 bytes of incrementing counter
  ]

  format pad_parts(parts)
end