{"id":13878026,"url":"https://github.com/pch/based_uuid","last_synced_at":"2025-09-12T11:31:23.066Z","repository":{"id":211057598,"uuid":"728097666","full_name":"pch/based_uuid","owner":"pch","description":"🔑 URL-friendly, base32-encoded UUIDs for Rails models","archived":false,"fork":false,"pushed_at":"2024-02-02T08:05:17.000Z","size":40,"stargazers_count":81,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-24T16:57:56.734Z","etag":null,"topics":["activerecord","rails","ruby","ruby-gem","ruby-on-rails"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-12-06T08:16:58.000Z","updated_at":"2025-06-07T16:18:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"b675553f-49cb-4d74-a4cf-5c6d1479543e","html_url":"https://github.com/pch/based_uuid","commit_stats":null,"previous_names":["pch/based_uuid"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/pch/based_uuid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pch%2Fbased_uuid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pch%2Fbased_uuid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pch%2Fbased_uuid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pch%2Fbased_uuid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pch","download_url":"https://codeload.github.com/pch/based_uuid/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pch%2Fbased_uuid/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274802500,"owners_count":25352589,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-12T02:00:09.324Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecord","rails","ruby","ruby-gem","ruby-on-rails"],"created_at":"2024-08-06T08:01:37.864Z","updated_at":"2025-09-12T11:31:22.187Z","avatar_url":"https://github.com/pch.png","language":"Ruby","readme":"# BasedUUID: URL-friendly UUIDs for Rails models\n\n[![Build Status](https://github.com/pch/based_uuid/workflows/Tests/badge.svg)](https://github.com/pch/based_uuid/actions)\n\nGenerate “double-clickable”, URL-friendly UUIDs with optional prefixes:\n\n```\nuser_763j02ryxh8dbs56mgcjqrmmgt #=\u003e e61c802c-7bb1-4357-929a-9064af8a521a\nbpo_12dm1qresn83st62reqdw7f7cv  #=\u003e 226d037c-3b35-40f3-a30b-0ebb78779d9b\n```\n\nThis gem encodes UUID primary keys into 26-character lowercase strings using [Crockford’s base32](https://www.crockford.com/base32.html) encoding. The optional prefix helps you identify the model it represents.\n\nBy default, BasedUUID assumes that you have a [UUID primary key](https://guides.rubyonrails.org/v5.0/active_record_postgresql.html#uuid) (`id`) in your ActiveRecord model. It doesn’t affect how UUIDs are stored in the database. Prefixes and base32-encoded strings are only used for presentation.\n\n## Installation\n\nAdd this line to your `Gemfile`:\n\n```ruby\ngem \"based_uuid\"\n```\n\n## Usage\n\nAdd the following line to your model class:\n\n```ruby\nclass BlogPost \u003c ApplicationRecord\n  has_based_uuid prefix: :bpo\nend\n\npost = BlogPost.last\npost.based_uuid                #=\u003e bpo_12dm1qresn83st62reqdw7f7cv\npost.based_uuid(prefix: false) #=\u003e 12dm1qresn83st62reqdw7f7cv\n\npost.based_uuid_with_prefix\npost.based_uuid_without_prefix\n```\n\n### Lookup\n\nBasedUUID includes a `find_by_based_uuid` model method to look up records:\n\n```ruby\nBlogPost.find_by_based_uuid(\"bpo_12dm1qresn83st62reqdw7f7cv\")\n\n# or without the prefix:\nBlogPost.find_by_based_uuid(\"12dm1qresn83st62reqdw7f7cv\")\n\n# there’s also the bang version:\nBlogPost.find_by_based_uuid!(\"12dm1qresn83st62reqdw7f7cv\")\n```\n\n### Generic lookup\n\nThe gem provides a generic lookup method to help you find the correct model for the UUID, based on prefix:\n\n```ruby\nBasedUUID.find(\"bpo_12dm1qresn83st62reqdw7f7cv\")\n#=\u003e #\u003cBlogPost\u003e\nBasedUUID.find(\"user_763j02ryxh8dbs56mgcjqrmmgt\")\n#=\u003e #\u003cUser\u003e\n```\n\n**⚠️ NOTE:** Rails lazy-loads models in the development environment, so this method won’t know about your models until you’ve referenced them at least once. If you’re using this method in a Rails console, you’ll need to run `BlogPost` (or any other model) before you can use it.\n\n### BasedUUID as default URL identifiers\n\nBasedUUID aims to be non-intrusive and it doesn’t affect how Rails URLs are generated, so if you want to use it as default URL param, add this to your model:\n\n```ruby\ndef to_param\n  based_uuid\nend\n```\n\n### Custom UUID column name\n\n`BasedUUID` will respect the value of `Model.primary_key`, so it supports custom primary key names:\n\n```ruby\nclass Transaction \u003c ApplicationRecord\n  self.primary_key = \"txid\"\n\n  has_based_uuid prefix: :tx\nend\n```\n\nIf you want to use a different column, other than the primary key, you can pass it as an option to `has_based_uuid`:\n\n```ruby\nclass Session \u003c ApplicationRecord\n  has_based_uuid prefix: :sid, uuid_column: :session_id\nend\n```\n\n### Use outside ActiveRecord\n\nBasedUUID can be used outside ActiveRecord, too. You can encode any UUID with it:\n\n```ruby\nBasedUUID.encode(uuid: \"226d037c-3b35-40f3-a30b-0ebb78779d9b\")\nBasedUUID.encode(uuid: \"226d037c-3b35-40f3-a30b-0ebb78779d9b\", prefix: :bpo)\nBasedUUID.decode(\"bpo_12dm1qresn83st62reqdw7f7cv\")\n```\n\n---\n\n## Development\n\nAfter 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.\n\nTo 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/pch/based_uuid.\n\n### Credits\n\nThis gem is heavily inspired by [Stripe IDs](https://stripe.com/docs/api) and the [prefixed_ids](https://github.com/excid3/prefixed_ids/tree/master) gem by Chris Oliver.\n\nParts of the base32 encoding code are borrowed from the [ulid](https://github.com/rafaelsales/ulid) gem by Rafael Sales.\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpch%2Fbased_uuid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpch%2Fbased_uuid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpch%2Fbased_uuid/lists"}