User eXperience focused IDentifiers (UXIDs) are identifiers which:
- Describe the resource (aid in debugging and investigation)
- Work well with copy and paste (double clicking selects the entire ID)
- Can be shortened for low cardinality resources
- Are secure against enumeration attacks
- Can be generated by application code (not tied to the datastore)
- Are K-sortable (lexicographically sortable by time - works well with datastore indexing)
- Do not require any coordination (human or automated) at startup, or generation
- Are very unlikely to collide (more likely with less randomness)
- Are easily and accurately transmitted to another human using a telephone
Many of the concepts of Stripe IDs have been used in this library.
# No options generates a basic ULID
UXID.generate # "01EMDGJF0DQXQJ8FM78XE97Y3H"
# A prefix can be provided
UXID.generate prefix: "cus" # "cus_01EMDGJF0DQXQJ8FM78XE97Y3H"
# The amount of entropy can be decreased for smaller cardinality resources
# T-Shirt sizes can be used (:xs, :s, :m, :l, :xl) or (:xsmall, :small, :medium, :large, :xlarge)
UXID.generate prefix: "cus", size: :small # "cus_01EQRH884AQYY1"
Add this line to your application's Gemfile:
gem "uxid"
And then execute:
$ bundle install
Or install it yourself as:
$ gem install uxid
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/riddler/uxid.
The gem is available as open source under the terms of the MIT License.