{"id":13879894,"url":"https://github.com/ankane/str_enum","last_synced_at":"2025-11-17T14:10:53.099Z","repository":{"id":56267087,"uuid":"71740290","full_name":"ankane/str_enum","owner":"ankane","description":"String enums for Rails","archived":false,"fork":false,"pushed_at":"2025-10-22T05:17:09.000Z","size":49,"stargazers_count":88,"open_issues_count":3,"forks_count":10,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-07T01:33:45.809Z","etag":null,"topics":[],"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/ankane.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-10-24T01:13:20.000Z","updated_at":"2025-11-04T09:50:50.000Z","dependencies_parsed_at":"2023-12-26T20:43:18.323Z","dependency_job_id":"b9a729d8-55d7-4f09-b46f-31728160f067","html_url":"https://github.com/ankane/str_enum","commit_stats":{"total_commits":59,"total_committers":5,"mean_commits":11.8,"dds":0.576271186440678,"last_synced_commit":"4543261cdd169c21d125b11571fc2d785f81cc6b"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/ankane/str_enum","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fstr_enum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fstr_enum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fstr_enum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fstr_enum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ankane","download_url":"https://codeload.github.com/ankane/str_enum/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fstr_enum/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283846898,"owners_count":26904663,"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-11-11T02:00:06.610Z","response_time":65,"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":[],"created_at":"2024-08-06T08:02:38.108Z","updated_at":"2025-11-17T14:10:53.082Z","avatar_url":"https://github.com/ankane.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# str_enum\n\nDon’t like storing enums as integers in your database? Introducing...\n\nString enums for Rails!! :tada:\n\n- scopes\n- validations\n- accessor methods\n- update methods\n\n[![Build Status](https://github.com/ankane/str_enum/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/str_enum/actions)\n\n## Getting Started\n\nAdd this line to your application’s Gemfile:\n\n```ruby\ngem \"str_enum\"\n```\n\nAdd a string column to your model.\n\n```ruby\nadd_column :users, :status, :string\n```\n\nAnd use:\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  str_enum :status, [:active, :archived]\nend\n```\n\nThe first value will be the initial value. This gives you:\n\n#### Scopes\n\n```ruby\nUser.active\nUser.archived\n```\n\nAnd negative scopes\n\n```ruby\nUser.not_active\nUser.not_archived\n```\n\n#### Validations\n\n```ruby\nuser = User.new(status: \"unknown\")\nuser.valid? # false\n```\n\n#### Accessor Methods\n\n```ruby\nuser.active?\nuser.archived?\n```\n\n#### Update Methods\n\n```ruby\nuser.active!\nuser.archived!\n```\n\n#### Forms\n\n```erb\n\u003c%= f.select :status, User.statuses.map { |s| [s.titleize, s] } %\u003e\n```\n\n## Options\n\nChoose which features you want with (default values shown):\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  str_enum :status, [:active, :archived],\n    accessor_methods: true,\n    allow_nil: false,\n    default: true,\n    prefix: false,\n    scopes: true,\n    suffix: false,\n    update_methods: true,\n    validate: true\nend\n```\n\nPrevent method name collisions with the `prefix` and `suffix` options.\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  str_enum :address_status, [:active, :archived], suffix: :address\nend\n\n# scopes\nUser.active_address\nUser.archived_address\n\n# accessor methods\nuser.active_address?\nuser.archived_address?\n\n# update methods\nuser.active_address!\nuser.archived_address!\n```\n\n## History\n\nView the [changelog](https://github.com/ankane/str_enum/blob/master/CHANGELOG.md)\n\n## Contributing\n\nEveryone is encouraged to help improve this project. Here are a few ways you can help:\n\n- [Report bugs](https://github.com/ankane/str_enum/issues)\n- Fix bugs and [submit pull requests](https://github.com/ankane/str_enum/pulls)\n- Write, clarify, or fix documentation\n- Suggest or add new features\n\nTo get started with development and testing:\n\n```sh\ngit clone https://github.com/ankane/str_enum.git\ncd str_enum\nbundle install\nbundle exec rake test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fstr_enum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fankane%2Fstr_enum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fstr_enum/lists"}