Class: BMC::SortableUUIDGenerator

Inherits:
Object
  • Object
show all
Defined in:
app/libs/bmc/sortable_uuid_generator.rb

Overview

Microtime based uuids to be sortable

Constant Summary collapse

REGEX_WITH_DASHES =
/^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/
REGEX_WITHOUT_DASHES =
/^([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})$/

Class Method Summary collapse

Class Method Details

.callObject



6
7
8
9
10
# File 'app/libs/bmc/sortable_uuid_generator.rb', line 6

def self.call
  prefix = Time.zone.now.strftime("%s%9N").to_i.to_s(16)
  suffix = SecureRandom.hex(8)
  (prefix + suffix).gsub(REGEX_WITHOUT_DASHES, '\1-\2-\3-\4-\5')
end