Module: SecureRandom

Defined in:
lib/uuid64.rb

Class Method Summary collapse

Class Method Details

.mongo_idObject



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

def self.mongo_id
  if @mongo_init.nil?
    @mongo_init = true.freeze
    @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
  else
    @mongo_inc += 1
  end

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

.mongo_id64Object



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

def self.mongo_id64
  [[SecureRandom.mongo_id].pack('H*')].pack('m').gsub(/\n/,'')
end

.uuid64Object



6
7
8
# File 'lib/uuid64.rb', line 6

def self.uuid64
  [[SecureRandom.uuid.gsub(/-/, '')].pack('H*')].pack('m').gsub(/==/,'').gsub(/\n/,'')
end