Module: SecureRandom
- Defined in:
- lib/uuid64.rb
Class Method Summary collapse
Class Method Details
.mongo_id ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/uuid64.rb', line 17 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_id62 ⇒ Object
35 36 37 |
# File 'lib/uuid64.rb', line 35 def mongo_id62 mongo_id.to_i(16).base62_encode end |
.mongo_id64 ⇒ Object
31 32 33 |
# File 'lib/uuid64.rb', line 31 def mongo_id64 [[mongo_id].pack('H*')].pack('m').chomp end |
.uuid62 ⇒ Object
13 14 15 |
# File 'lib/uuid64.rb', line 13 def uuid62 uuid.delete('-').to_i(16).base62_encode end |
.uuid64 ⇒ Object
9 10 11 |
# File 'lib/uuid64.rb', line 9 def uuid64 [[uuid.delete('-')].pack('H*')].pack('m').delete('=').chomp end |