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

Add DSL for enums #69

Open
palexander opened this issue Feb 2, 2013 · 2 comments
Open

Add DSL for enums #69

palexander opened this issue Feb 2, 2013 · 2 comments
Assignees
Milestone

Comments

@palexander
Copy link
Member

Handle Java-style enum objects that allow for a definition of allowed values that get created automatically on first access with a static flag to avoid recreating the values again.

class UserRole
  enum_values :administrator, :librarian, :developer
end

For retrieving, two possible syntax options:

u = UserRole.new(role: "ADMINISTRATOR")
=> Exception "Enums cannot be instantiated, only found)
u = UserRole.find("ADMINISTRATOR")
=> <UserRole: {role: "ADMINISTRATOR"}>

Or get rid of new (by making initialize private) and find and use one method per enum value:

UserRole.default
UserRole.administrator
@ghost ghost assigned msalvadores Feb 2, 2013
@msalvadores
Copy link
Member

In

UserRole.default

How do we know which enum instance is default ? do we need an option for that like:

class UserRole
  enum_values :administrator, :librarian, :developer, :default => :librarian
end

@palexander
Copy link
Member Author

Yes, UserRole.default is just a hard-coded method with the default value, so if we want that functionality in the DSL then it would make sense to have an option available

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