{"id":15681730,"url":"https://github.com/mattpolito/slugworth","last_synced_at":"2025-05-07T09:42:42.482Z","repository":{"id":55016658,"uuid":"11093049","full_name":"mattpolito/slugworth","owner":"mattpolito","description":"Simple slug functionality for your ActiveRecord objects","archived":false,"fork":false,"pushed_at":"2022-04-01T02:05:36.000Z","size":37,"stargazers_count":10,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-13T14:35:53.814Z","etag":null,"topics":["permalink","url-slug"],"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/mattpolito.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["mattpolito"]}},"created_at":"2013-07-01T11:35:46.000Z","updated_at":"2021-01-15T01:39:24.000Z","dependencies_parsed_at":"2022-08-14T09:10:32.594Z","dependency_job_id":null,"html_url":"https://github.com/mattpolito/slugworth","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattpolito%2Fslugworth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattpolito%2Fslugworth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattpolito%2Fslugworth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattpolito%2Fslugworth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattpolito","download_url":"https://codeload.github.com/mattpolito/slugworth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252852567,"owners_count":21814380,"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":["permalink","url-slug"],"created_at":"2024-10-03T16:59:25.689Z","updated_at":"2025-05-07T09:42:42.459Z","avatar_url":"https://github.com/mattpolito.png","language":"Ruby","funding_links":["https://github.com/sponsors/mattpolito"],"categories":[],"sub_categories":[],"readme":"![Slugworth](http://f.cl.ly/items/3T1K3g040S0u2l0G0d3V/slugworth_header.png)\n\n[![Gem Version](http://img.shields.io/gem/v/slugworth.svg?style=flat)](http://badge.fury.io/rb/slugworth)\n[![Build Status](https://img.shields.io/github/workflow/status/mattpolito/slugworth/CI)](https://github.com/mattpolito/slugworth/actions?query=workflow%3ACI)\n\nSimple slug functionality for your ActiveRecord objects\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```shell\n  gem 'slugworth'\n```\n\nand then execute\n\n```shell\n  bundle\n```\n\nor\n\ninstall it yourself with\n\n```shell\n  gem install slugworth\n```\n\n## Usage\n\nGetting started is easy! Just ensure that your model has a database column of type `String` called `slug`\n\nTo use, just add two declarations to your `ActiveRecord` class and away you go!\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  include Slugworth\n  slugged_with :name\nend\n```\n\nAfter you `include` the `Slugworth` module, all you need to do is declare what method will be used to create the slug. The method passed to `slugged_with` will then be parameterized.\n\nThis provides most of the default slug functionality you would need.\n\n* Finders `.find_by_slug` \u0026 `.find_by_slug!` are provided. This will, of course, do what you expect and find a single record by the slug attribute provided.\n* `#to_param` has been defined as a parameterized version of the attribute declared to `slugged_with`.\n* Validations stating that `slug` is present and unique in the database.\n\n### Scoping uniqueness\n\nBy default the slug is unique to the entire table, but you can specify the scope of the uniqueness as the following:\n\n```ruby\nclass Product \u003c ActiveRecord::Base\n  include Slugworth\n  belongs_to :user\n  slugged_with :name, scope: :user_id\nend\n```\n\n### Updating slugs\n\nSometimes you want to update the slug if the attribute is changed.\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  include Slugworth\n  slugged_with :name, updatable: true\nend\n\nuser = User.create(name: 'Jack')\n=\u003e User(id: 1, name: 'Jack', slug: 'jack')\n\nuser.update_attribute(:name, 'John')\n=\u003e User(id: 1, name: 'John', slug: 'john')\n```\n\n### Incremental slugs\n\nIf another record already exists with the same slug it will generate an uniqueness validation error, but if incremental slugs is enabled, then it will append an incremented number to the slug:\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  include Slugworth\n  slugged_with :name, incremental: true\nend\n\nUser.create(name: 'Jack')\n=\u003e User(id: 1, name: 'Jack', slug: 'jack')\n\nUser.create(name: 'Jack')\n=\u003e User(id: 2, name: 'Jack', slug: 'jack-1')\n```\n\n## Test Helper\n\nTo aid in testing your models that implement the Slugworth functionality, I've added a shared example group that can be added to your test suite. Add this to your `spec_helper.rb`\n\n```ruby\ninclude 'slugworth_shared_examples'\n```\n\nAnd then in your specs just add:\n\n```ruby\nit_behaves_like :has_slug_functionality\n```\n\nThis will add the same specs to your model that get run on Slugworth itself!\n\n## Contributing\n\n1. Fork it\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 new Pull Request\n\n## Thanks\n\n* [Rye Mason][] for the fantastic heading image.\n\n[Rye Mason]: https://github.com/ryenotbread\n\n## About\n\n[![Hashrocket logo](https://hashrocket.com/hashrocket_logo.svg)](https://hashrocket.com)\n\nSlugworth is supported by the team at [Hashrocket, a\nmultidisciplinary design and development consultancy](https://hashrocket.com). If you'd like to [work with us](https://hashrocket.com/contact-us/hire-us) or [join our team](https://hashrocket.com/contact-us/jobs), don't hesitate to get in touch.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattpolito%2Fslugworth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattpolito%2Fslugworth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattpolito%2Fslugworth/lists"}