Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enums support #76

Open
dnagir opened this issue Feb 17, 2012 · 1 comment
Open

Enums support #76

dnagir opened this issue Feb 17, 2012 · 1 comment

Comments

@dnagir
Copy link

dnagir commented Feb 17, 2012

Ability to write something like:

class Filter
  include ActiveAttr::Model

  attribute :status, default: :all, enum: [:all, :available, :unavailable]
end

This would give us:

  • Filter#status_name that is i8n translated based on the value of Filter#status.
  • Filtet#status_hashes - the hash that can be used on the views.
  • Assigning any valid outside of the given range would throw by default.
  • Ability to use it with ActiveModel as well as ActiveRecord (and hooks for other ORMs if possible).

There's simple_enum and similar, but those seem to be tight to AR.

The implementation is pretty straightforward (for AR-only). This is what I'm currently using which may be a good start.

@johnnyshields
Copy link

This should be revisited with Enums now being added to Rails 4.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants