{"id":19474552,"url":"https://github.com/tomasc/mongoid-enum_attribute","last_synced_at":"2025-10-12T00:45:33.830Z","repository":{"id":56884373,"uuid":"131716749","full_name":"tomasc/mongoid-enum_attribute","owner":"tomasc","description":"Take on ActiveRecord::Enum in Mongoid","archived":false,"fork":false,"pushed_at":"2023-11-21T21:26:04.000Z","size":20,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-03T22:23:09.836Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomasc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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":"2018-05-01T13:34:12.000Z","updated_at":"2023-11-21T20:54:40.000Z","dependencies_parsed_at":"2024-11-10T19:25:41.820Z","dependency_job_id":null,"html_url":"https://github.com/tomasc/mongoid-enum_attribute","commit_stats":{"total_commits":16,"total_committers":3,"mean_commits":5.333333333333333,"dds":0.25,"last_synced_commit":"6b3019958bd8ef6138d43f3194a3daf03ce53f2b"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasc%2Fmongoid-enum_attribute","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasc%2Fmongoid-enum_attribute/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasc%2Fmongoid-enum_attribute/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasc%2Fmongoid-enum_attribute/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomasc","download_url":"https://codeload.github.com/tomasc/mongoid-enum_attribute/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250146268,"owners_count":21382594,"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-10T19:25:36.895Z","updated_at":"2025-10-12T00:45:28.792Z","avatar_url":"https://github.com/tomasc.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mongoid::EnumAttribute\n\n[![Build Status](https://travis-ci.org/tomasc/mongoid-enum_attribute.svg)](https://travis-ci.org/tomasc/mongoid-enum_attribute) [![Gem Version](https://badge.fury.io/rb/mongoid-enum_attribute.svg)](http://badge.fury.io/rb/mongoid-enum_attribute) [![Coverage Status](https://img.shields.io/coveralls/tomasc/mongoid-enum_attribute.svg)](https://coveralls.io/r/tomasc/mongoid-enum_attribute)\n\nUpdated and tweaked version of the no-longer-maintained [mongoid_enum](https://github.com/thetron/mongoid-enum).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'mongoid-enum_attribute'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install mongoid-enum_attribute\n\n## Usage\n\n```ruby\nclass Payment\n  include Mongoid::Document\n  include Mongoid::EnumAttribute\n\n  enum :status, [:pending, :approved, :declined]\nend\n```\n\nGives you getters,\n\n```ruby\npayment.status\n# =\u003e :pending\n```\n\nsetters,\n\n```ruby\npayment.approved!\n# =\u003e :approved\n```\n\nconditionals,\n\n```ruby\npayment.pending?\n# =\u003e :false\n```\n\nand scopes\n\n```ruby\nPayment.approved\n# =\u003e Mongoid::Criteria for payments where status is :approved\n```\n\n## Prefix / Suffix\n\nYou can use the `:prefix` and `:suffix` options, to prefix or suffix the methods\nof the enum. If the passed value is `true`, the methods are prefixed/suffixed\nwith the name of the enum. It is also possible to supply a custom value:\n\n```ruby\nenum :status, [:pending, :approved, :declined], prefix: true\nenum :payments_status, [:pending, :approved, :declined], prefix: :payments\n\nenum :status, [:pending, :approved, :declined], suffix: true\nenum :payments_status, [:pending, :approved, :declined], suffix: :payments\n```\n\nThis will result in the following methods:\n\n```ruby\npayment.status_declined! # prefix: true\npayment.payments_declined! # prefix: :payments\n\npayment.declined_status! # suffix: true\npayment.declined_payments! # suffix: :payments\n```\n\nIf you want to change the behaviour app-wide you can use the configuration:\n\n```ruby\nMongoid::EnumAttribute.configure do |config|\n  config.field_name_prefix = '_' # prefix of the field used to store the values in database\n  config.prefix = nil # prefix of the ! \u0026 ? method\n  config.suffix = nil # suffix of the ! \u0026 ? method\nend\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/tomasc/mongoid-enum_attribute.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomasc%2Fmongoid-enum_attribute","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomasc%2Fmongoid-enum_attribute","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomasc%2Fmongoid-enum_attribute/lists"}