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-2.0.0 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.11.0 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.10.5 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.10.2 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.10.1 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.10.0 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.9.20 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.9.19 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.9.18 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.9.17 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.9.16 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.9.15 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.9.14 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.9.13 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.9.12 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.9.11 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.9.10 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.9.9 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.9.8 app/libs/agilibox/sortable_uuid_generator.rb
agilibox-1.9.7 app/libs/agilibox/sortable_uuid_generator.rb