Sha256: 5eb738959d1d9ef0dcf45ac7564f3f11a9499cb9a4576626e54f79dd514a2ead

Contents?: true

Size: 459 Bytes

Versions: 55

Compression:

Stored size: 459 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
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
agilibox-1.5.8 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.5.7 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.5.6 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.5.5 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.5.4 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.5.3 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.5.2 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.5.1 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.5.0 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.4.4 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.4.3 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.4.2 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.4.1 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.4.0 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.3.6 app/libs/agilibox/sortable_uuid_generator.rb