{"id":28589590,"url":"https://github.com/ZephiroRB/has_tokenable","last_synced_at":"2025-06-11T08:10:03.738Z","repository":{"id":56876043,"uuid":"260141105","full_name":"ZephiroRB/has_tokenable","owner":"ZephiroRB","description":"Identify your active records with random tokens when you don't want your users to see a sequential ID https://rubygems.org/gems/has_tokenable","archived":false,"fork":false,"pushed_at":"2020-07-16T07:26:44.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-06T14:49:13.163Z","etag":null,"topics":["gem","rails","security"],"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/ZephiroRB.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-30T07:20:56.000Z","updated_at":"2020-07-16T07:26:46.000Z","dependencies_parsed_at":"2022-08-20T23:10:24.086Z","dependency_job_id":null,"html_url":"https://github.com/ZephiroRB/has_tokenable","commit_stats":null,"previous_names":["carlangasgo/has_tokenable"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZephiroRB%2Fhas_tokenable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZephiroRB%2Fhas_tokenable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZephiroRB%2Fhas_tokenable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZephiroRB%2Fhas_tokenable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZephiroRB","download_url":"https://codeload.github.com/ZephiroRB/has_tokenable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZephiroRB%2Fhas_tokenable/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259227959,"owners_count":22824904,"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","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":["gem","rails","security"],"created_at":"2025-06-11T08:10:01.559Z","updated_at":"2025-06-11T08:10:03.727Z","avatar_url":"https://github.com/ZephiroRB.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Identify your active records with random tokens when you don't want your users to see a sequential ID.\n\n\n------------------------------------------------------------------------------\nInstallation\n------------------------------------------------------------------------------\n\nAdd has_tokenable to your Gemfile like so:\n\n```ruby\ngem 'has_tokenable', '~\u003e 0.1.0'\n```\n\nNow run `bundle install` and you're good to go!\n\n\n------------------------------------------------------------------------------\nUsage\n------------------------------------------------------------------------------\n\nFirst, add a token to your model's table with a migration:\n\n```ruby\n# Upgrade and existing table\nclass AddTokenToItems \u003c ActiveRecord::Migration\n  add_column :items, :token, :string\nend\n\n# Add to a new table\nclass CreateItems \u003c ActiveRecord::Migration\n  def change\n    create_table :items do |t|\n      t.token\n      t.string :name\n\n      t.timestamps\n    end\n  end\nend\n```\n\n\nNow make sure your model knows to use it's token by calling `has_tokenable`\n\n```ruby\nclass Item \u003c ActiveRecord::Base\n  has_tokenable  \nend\n```\n\nThat's basically it! Your Items will now know to use their token as their identifier.\n\nTry it out in your `rails console`\n\n```ruby\n@item = Item.create(name: \"Tokenz!\")\n#\u003cItem id: 1, token: \"B5OvJvy6B2_DZg\", name: \"Tokenz!\", created_at: \"2020-01-26 20:17:13\", updated_at: \"2020-01-26 20:17:13\"\u003e\n@item.to_param\n# B5OvJvy6B2_DZg\n@item == Item.find(\"B5OvJvy6B2_DZg\")\n# true\n```\n\n\n------------------------------------------------------------------------------\nOptions\n------------------------------------------------------------------------------\n\nYou can customize has_tokenable by setting a few options. Here's the defaults:\n\n```ruby\n{\n  prefix:             nil, # if nil use first letter of class name\n  length:             10,\n  param_name:         'token',\n  method_random:      'urlsafe_base64' #method random urlsafe_base64 hex alphanumeric random_number uuid\n}\n```\n\n\nOptions can be set globally by overwriting the `HasTokenable.default_token_options`\n\n```ruby\n# config/initializers/has_tokenable.rb\n\n# for one option\nHasTokenable.default_token_options[:prefix] = \"OMG\"\n\n# for multiple options\nHasTokenable.default_token_options.merge!(\n  method_random:      'alphanumeric',\n  length:         8\n)\n```\n\nOptions can also be set on a per-class level:\n\n```ruby\nclass List \u003c ActiveRecord::Base\n  has_tokenable prefix: \"LI\", length: 10\nend\n\nclass Item \u003c ActiveRecord::Base\n  has_tokenable prefix: \"ITM\"\nend\n```\n\n\n------------------------------------------------------------------------------\nDemo\n------------------------------------------------------------------------------\n\nTry out the demo to get a real clear idea of what has_tokenable does.\n\n```bash\ngit clone git://github.com/CarlangasGO/has_tokenable.git\ncd has_tokenable\nbundle install\nrails s\n```\n\nNow open your browser to [http://localhost:3000](http://localhost:3000)\n\n\n------------------------------------------------------------------------------\nLicense\n------------------------------------------------------------------------------\n\nCopyright (c) 2019 - 2020, released under the New BSD License All rights reserved.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FZephiroRB%2Fhas_tokenable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FZephiroRB%2Fhas_tokenable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FZephiroRB%2Fhas_tokenable/lists"}