Module: SecureRandom

Defined in:
lib/uuid64.rb

Class Method Summary collapse

Class Method Details

.mongo_idObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/uuid64.rb', line 12

def mongo_id
  @mongo_host ||= Digest::SHA2.hexdigest(Socket.gethostname)[0..5].freeze
  @mongo_pid ||= Process.pid.to_s(16)[0..3].rjust(4, '0').freeze

  @mongo_inc ||= 0
  @mongo_inc += 1
  @mongo_inc = 0 if @mongo_inc > 16_777_215

  Time.now.to_i.to_s(16)[0..7].rjust(8, '0') +
    @mongo_host +
    @mongo_pid +
    @mongo_inc.to_s(16)[0..5].rjust(6, '0')
end

.mongo_id64Object



26
27
28
# File 'lib/uuid64.rb', line 26

def mongo_id64
  [[mongo_id].pack('H*')].pack('m').chomp
end

.uuid64Object



8
9
10
# File 'lib/uuid64.rb', line 8

def uuid64
  [[uuid.delete('-')].pack('H*')].pack('m').delete('=').chomp
end