{"id":26894142,"url":"https://github.com/panorama-ed/unique_attributes","last_synced_at":"2025-07-31T08:08:50.159Z","repository":{"id":25506403,"uuid":"28937848","full_name":"panorama-ed/unique_attributes","owner":"panorama-ed","description":"Auto-assign unique attributes for ActiveRecord objects","archived":false,"fork":false,"pushed_at":"2023-11-29T20:20:52.000Z","size":43,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":42,"default_branch":"main","last_synced_at":"2025-07-16T18:13:06.235Z","etag":null,"topics":["open-source","rails","ruby"],"latest_commit_sha":null,"homepage":null,"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/panorama-ed.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-01-07T22:44:43.000Z","updated_at":"2023-03-13T17:11:58.000Z","dependencies_parsed_at":"2025-03-21T22:40:36.574Z","dependency_job_id":null,"html_url":"https://github.com/panorama-ed/unique_attributes","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/panorama-ed/unique_attributes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panorama-ed%2Funique_attributes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panorama-ed%2Funique_attributes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panorama-ed%2Funique_attributes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panorama-ed%2Funique_attributes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/panorama-ed","download_url":"https://codeload.github.com/panorama-ed/unique_attributes/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panorama-ed%2Funique_attributes/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268010103,"owners_count":24180459,"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-07-31T02:00:08.723Z","response_time":66,"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":["open-source","rails","ruby"],"created_at":"2025-04-01T00:00:08.490Z","updated_at":"2025-07-31T08:08:50.127Z","avatar_url":"https://github.com/panorama-ed.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Code Coverage](https://codecov.io/gh/panorama-ed/unique_attributes/branch/main/graph/badge.svg)](https://codecov.io/gh/panorama-ed/unique_attributes)\n[![Inline docs](http://inch-ci.org/github/panorama-ed/unique_attributes.png)](http://inch-ci.org/github/panorama-ed/unique_attributes)\n[![Build Status](https://travis-ci.com/panorama-ed/unique_attributes.svg)](https://travis-ci.com/panorama-ed/unique_attributes)\n[![Gem Version](https://badge.fury.io/rb/unique_attributes.svg)](http://badge.fury.io/rb/unique_attributes)\n\n# UniqueAttributes\n\nUniqueAttributes gives you an easy way to ensure that autogenerated fields on\nyour ActiveRecord models are unique.\n\nAuto-assign usernames for your users? You've come to the right place.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'unique_attributes'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install unique_attributes\n\n## Usage\n\n```ruby\nrequire \"unique_attributes\"\n\nclass User \u003c ActiveRecord::Base\n  include UniqueAttributes\n\n  unique_attribute :username, proc { SecureRandom.hex }\nend\n```\n\nVoilà! Now let's see how it works:\n\n```ruby\n\u003e user = User.new\n\u003e user.username\n=\u003e nil\n\u003e user.save!\n\u003e user.username\n=\u003e \"1a4523822c1a2bebdfc0c036c94f1e0e\"\n```\n\nYour user now has a username that's automatically set via the proc you specify,\nand it's guaranteed to be unique among all users.\n\nYou can still change the value at any time:\n```ruby\n\u003e user.username = \"Grace Hopper\"\n\u003e user.save!\n\u003e user.username\n=\u003e \"Grace Hopper\"\n```\n\nWhat if the uniqueness is scoped by something? No problem:\n```ruby\nunique_attribute :username, proc { SecureRandom.hex }, scope: :group_id\n```\n\nYou can pass in any scopes you could pass into a Rails uniqueness validation.\nNow:\n```ruby\n\u003e user1 = User.new(group_id: 1)\n\u003e user2 = User.new(group_id: 1)\n\u003e user3 = User.new(group_id: 2)\n```\n\nBecause `user1` and `user2` are in the same uniqueness scope, we are guaranteed\nto give them different usernames. `user3` could have the same username as either\nof them since it's outside the uniqueness scope.\n\n-----\n\n**Note that UniqueAttributes assumes you have an accompanying unique\nindex in your database:**\n```ruby\nadd_index :users, :username, unique: true\n```\n\nor, in the case of a scoped uniqueness:\n```ruby\nadd_index :users, [:username, :group_id], unique: true\n```\n\n## Database Compatibility\n\nUniqueAttributes currently supports **PostgreSQL** and **SQLite3**, though\nadding support for your favorite database adapter is as easy as writing a regex\nto parse its uniqueness violation error messages. (Note that MySQL's messages do\nnot give granular enough output and thus are not supported currently. Maybe you\ncan come up with a fix?)\n\n## Contributing\n\n1. Fork it (https://github.com/panorama-ed/unique_attributes/fork)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n**Make sure your changes have appropriate tests (`bundle exec rspec`)\nand conform to the Rubocop style specified.** We use\n[overcommit](https://github.com/causes/overcommit) to enforce good code.\n\n## License\n\nUniqueAttributes is released under the\n[MIT License](https://github.com/panorama-ed/unique_attributes/blob/main/LICENSE.txt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpanorama-ed%2Funique_attributes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpanorama-ed%2Funique_attributes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpanorama-ed%2Funique_attributes/lists"}