Sha256: b8b7339e2313a52a9c5cee5947e74eab99e159ca899948265fc237ed4170bf90

Contents?: true

Size: 557 Bytes

Versions: 8

Compression:

Stored size: 557 Bytes

Contents

# Microtime based uuids to be sortable
class Agilibox::SortableUUIDGenerator
  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})$/

  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

  def self.generate
    warn "#{self}::generate is deprecared, please use ::call"
    call
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
agilibox-1.3.5 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.3.4 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.3.3 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.3.2 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.3.1 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.3.0 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.2.3 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.2.2 app/libs/agilibox/sortable_uuid_generator.rb