{"id":19984633,"url":"https://github.com/twilightcoders/enumerate","last_synced_at":"2025-06-14T05:33:49.236Z","repository":{"id":11546510,"uuid":"14031878","full_name":"TwilightCoders/enumerate","owner":"TwilightCoders","description":"Enumerate adds an `enumerate` command to all ActiveRecord models which enables you to work with integer and string attributes as if they were enums","archived":false,"fork":false,"pushed_at":"2014-03-18T20:27:38.000Z","size":184,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-13T06:48:16.427Z","etag":null,"topics":[],"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/TwilightCoders.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":"2013-11-01T00:26:41.000Z","updated_at":"2014-03-18T20:27:38.000Z","dependencies_parsed_at":"2022-09-22T23:50:53.258Z","dependency_job_id":null,"html_url":"https://github.com/TwilightCoders/enumerate","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwilightCoders%2Fenumerate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwilightCoders%2Fenumerate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwilightCoders%2Fenumerate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwilightCoders%2Fenumerate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TwilightCoders","download_url":"https://codeload.github.com/TwilightCoders/enumerate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241419117,"owners_count":19959857,"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":[],"created_at":"2024-11-13T04:19:43.580Z","updated_at":"2025-03-01T20:22:59.481Z","avatar_url":"https://github.com/TwilightCoders.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Enumerate [![Build Status](https://secure.travis-ci.org/TwilightCoders/enumerate.png)](http://travis-ci.org/TwilightCoders/enumerate) [![Gem Version](https://badge.fury.io/rb/enumerate.png)](http://badge.fury.io/rb/enumerate) [![Code Climate](https://codeclimate.com/github/TwilightCoders/enumerate.png)](https://codeclimate.com/github/TwilightCoders/enumerate)\n\nEnumerate adds an enum command to all ActiveRecord models which enables you to work with integer and string attributes as if they were enums\n\n## Installing\n\nJust add the enumerate gem to your GemFile\n\n```ruby\ngem 'enumerate'\n```\n\n## How to use\n\nJust call the enum function in any ActiveRecord object, the function accepts the field name as the first variable and the possible values as an array\n\n```ruby\nclass Event \u003c ActiveRecord::Base\n    enum :status, [:available, :canceled, :completed]\nend\n```\n\nIf your status column is of type integer, Enumerate will assign the indices of the array as the values stored in the database.\n\n:available will be 0\n:canceled will be 1\n:completed will be 2\n\nIf you wish to specify yourself, simply use a hash\n\n```ruby\nclass Event \u003c ActiveRecord::Base\n    enum :status, {:available =\u003e 0, :canceled =\u003e 2, :completed =\u003e 5}\nend\n```\n\nAfter that you get several autogenerated commands to use with the enum\n\n```ruby\n# Access through field name\n\nevent.status                # returns the enum's current value as a symbol\nevent.status = :canceled    # sets the enum's value to canceled (can also get a string)\n\n\n# Shorthand methods, access through the possible values\n\nevent.available?            # returns true if enum's current status is available\nevent.canceled!             # changes the enum's value to canceled\n\n# Get all the possible values\n\nEvent::STATUSES             # returns all available status of the enum\n```\n\n## Options\n#### :allow_nil\nBy default the enum field does not support a nil value. In order to allow nil values add the `allow_nil` option (similar to the Rails validation option).\n\n```ruby\nclass Event \u003c ActiveRecord::Base\n    enum :status, [:available, :canceled, :completed], :allow_nil =\u003e true\nend\n\nEvent.create! # Is valid and does not throw an exception.\n```\n\n## Scopes\nOne last thing that the enumerate gem does is created scope (formerly nested_scopes) so you can easly query by the enum\n\nFor example if you want to count all the events that are canceled you can just run\n\n```ruby\nEvent.canceled.count\n```\n\n---\n\nCopyright (c) 2013 Dale Stevens, released under the MIT license\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwilightcoders%2Fenumerate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwilightcoders%2Fenumerate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwilightcoders%2Fenumerate/lists"}