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.9.6 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.9.5 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.9.4 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.9.3 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.9.1 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.9.0 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.8.0 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.7.4 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.7.3 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.7.2 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.7.1 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.7.0 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.6.2 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.6.1 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.6.0 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.5.13 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.5.12 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.5.11 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.5.10 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.5.9 app/libs/agilibox/sortable_uuid_generator.rb