{"id":15655708,"url":"https://github.com/huacnlee/enumize","last_synced_at":"2025-11-11T18:32:35.894Z","repository":{"id":45368285,"uuid":"193424491","full_name":"huacnlee/enumize","owner":"huacnlee","description":"Extend ActiveRecord::Enum for add more helpful methods.","archived":false,"fork":false,"pushed_at":"2023-10-12T03:41:47.000Z","size":42,"stargazers_count":24,"open_issues_count":2,"forks_count":3,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-07T16:55:22.665Z","etag":null,"topics":["enum","i18n","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/huacnlee.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"publiccode":null,"codemeta":null}},"created_at":"2019-06-24T03:02:21.000Z","updated_at":"2024-01-02T09:54:32.000Z","dependencies_parsed_at":"2024-08-21T19:16:57.139Z","dependency_job_id":null,"html_url":"https://github.com/huacnlee/enumize","commit_stats":{"total_commits":14,"total_committers":1,"mean_commits":14.0,"dds":0.0,"last_synced_commit":"39e05f5754299a3969f1b98bd32c2f2f7a16c9d0"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/huacnlee/enumize","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huacnlee%2Fenumize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huacnlee%2Fenumize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huacnlee%2Fenumize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huacnlee%2Fenumize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huacnlee","download_url":"https://codeload.github.com/huacnlee/enumize/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huacnlee%2Fenumize/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283910127,"owners_count":26915128,"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":["enum","i18n","rails"],"created_at":"2024-10-03T13:00:23.944Z","updated_at":"2025-11-11T18:32:35.878Z","avatar_url":"https://github.com/huacnlee.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Enumize\n\n[![build](https://github.com/huacnlee/enumize/actions/workflows/build.yml/badge.svg)](https://github.com/huacnlee/enumize/actions/workflows/build.yml)\n\nExtend [ActiveRecord::Enum](https://api.rubyonrails.org/classes/ActiveRecord/Enum.html) for add more helpful methods, from [rails/rails#36503](https://github.com/rails/rails/pull/36503).\n\n\u003e 🚨 This Gem does not change the way you use ActiveRecord::Enum, just adds method extensions.\n\n[中文介绍与使用说明](https://ruby-china.org/topics/38728)\n\n## Usage\n\n```rb\nclass Book\n  enum status: %i[draft published archived]\nend\n```\n\nNow we have `status_name`, `status_color`, `status_value` and `Book.status_options` methods:\n\n- `#{attribute}_name` - return I18n name for display.\n- `#{attribute}_color` - return color for enum value from I18n file.\n- `#{attribute}_value` - return raw value for enum, Now we don't need use `Book.statuses[@book.status]`.\n- `Book.#{attribute}_options` - return a array list for select tag options, `\u003c%= f.select :status, Book.status_options %\u003e`.\n\nWrite I18n:\n\n```yml\nen:\n  activerecord:\n    enums:\n      book:\n        status:\n          draft: Drafting\n          published: Published\n          archived: Archived\n        status_color:\n          draft: '#999999'\n          published: 'green'\n          archived: 'red'\n\nzh-CN:\n  activerecord:\n    enums:\n      book:\n        status:\n          draft: '草稿'\n          published: '已发布'\n          archived: '归档'\n```\n\nuse the methods:\n\n```rb\nirb\u003e @book = Book.new(status: :draft)\nirb\u003e @book.status_value\n0\nirb\u003e @book.status_name\n\"草稿\"\nirb\u003e @book.status_color\n\"#999999\"\n# You can still use the original methods from ActiveRecord::Enum\nirb\u003e @book.status\n\"draft\"\nirb\u003e @book.draft?\ntrue\nirb\u003e @book.published!\nirb\u003e @book.published?\ntrue\nirb\u003e @book.status\n\"published\"\n```\n\nFor `_options` methods for `select` helper:\n\n```erb\n\u003c% form_for(@book) do |f| %\u003e\n  \u003c%= f.text_field :name %\u003e\n  \u003c%= f.select :status, Book.status_options %\u003e\n  \u003c%= f.submit %\u003e\n\u003c% end \u003e\n```\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'enumize'\n```\n\nAnd then execute:\n\n```bash\n$ bundle\n```\n\n## Configure the I18n fallbacks for `color` method\n\nYou can write color config in `en.yml` once for all locales, so follow the I18n fallback, the others locale will\nuse color value from `en`:\n\nconfig/application.rb\n\n```rb\nmodule Dummy\n  class Application \u003c Rails::Application\n    # Add to tell I18n fallback translate to en\n    config.i18n.available_locales = [\"en\", \"zh-CN\"]\n    config.i18n.fallbacks = true\n  end\nend\n```\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuacnlee%2Fenumize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuacnlee%2Fenumize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuacnlee%2Fenumize/lists"}