rails-style-guide
rails-style-guide copied to clipboard
Enum: better styling
We suggest the kwargs-style enum definition:
enum type: {
credit: 0,
debit: 1
}
This is problematic in two ways.
- Passing options like
prefix/suffix/scopes/defaultis complicated (needs to be prefixed with an underscore) and is not documented - Results in weird unrelated errors (mentions the very first defined enum instead of the one that has options)
Ok to change this to use positional args for name and values?
enum :type, {
credit: 0,
debit: 1
}
With options:
enum :type, {
credit: 0,
debit: 1
}, suffix: true
Not sure if you're aware, but there's a cop for this now: https://github.com/rubocop/rubocop-rails/pull/1336 It is only is for Ruby >= 3.0 because on 2.7 it can cause keyword argument warnings (https://github.com/rubocop/rubocop-rails/pull/1363). The new syntax itself was introduced with Rails 7.0
@koic @andyw8 wdyt?
Off-topic: Rails 6.1 is EOL a month ago, is it a good idea to scrub the guide from legacy content, and leave a note that pre-7 guidelines are only kept in the GitHub repo (in a branch).?