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

Rename the enum_prefix and enum_suffix options to _prefix and _suffix #20999

Merged
merged 1 commit into from
Jul 23, 2015
Merged

Rename the enum_prefix and enum_suffix options to _prefix and _suffix #20999

merged 1 commit into from
Jul 23, 2015

Conversation

robin850
Copy link
Member

Hello,

This pull request renames the enum_{prefix_suffix} options to _{prefix_suffix} in order to make it more clear that they are reserved keywords and also it seems less redundant as the line already starts with the call to the enum method.

Cross-refs #19813 (comment).

Have a nice day.

This makes it more clear that they are reserved keywords and also it
seems less redundant as the line already starts with the call to the
`enum` method.
kaspth added a commit that referenced this pull request Jul 23, 2015
Rename the enum_prefix and enum_suffix options to _prefix and _suffix
@kaspth kaspth merged commit 2028b57 into rails:master Jul 23, 2015
@kaspth
Copy link
Contributor

kaspth commented Jul 23, 2015

Sweet, thanks! Have a nice day too 😄

@robin850 robin850 deleted the enum-prefix-suffix branch July 23, 2015 12:36
@robin850
Copy link
Member Author

Thanks! :-)

# Note that <tt>:enum_prefix</tt>/<tt>:enum_suffix</tt> are reserved keywords
# and can not be used as an enum name.
# Note that <tt>:_prefix</tt>/<tt>:_suffix</tt> are reserved keywords and can
# not be used as enum names.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably ✂️ now? Seems unlikely that people would try to use _ names, so while it's technically still true, it is just adding noise to me. What do you think?

Would trade that with an example of the feature. It doesn't really explain what the feature does, if you didn't know about the history here it seems unlikely that you would understand what it does/why you would need it from reading the docs here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to define multiple enums with same values

would be nice if the examples actually show that use case 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're totally right! 👍 Will send a patch then!

robin850 added a commit that referenced this pull request Jul 23, 2015
The note regarding the `_prefix` and `_suffix` options is no longer
useful since they were renamed specifically for this purpose.

Also the given example doesn't show what these options enable and in
which case they are really useful (when there are conflicting values
for instance).

Refs #20999.

[Godfrey Chan & Robin Dupret]
y-yagi added a commit to y-yagi/rails that referenced this pull request May 29, 2016
… skip]

`:enum_prefix` and `:enum_suffix` was changed to `:_prefix` and `:_suffix`
in rails#20999.
kamipo added a commit to kamipo/rails that referenced this pull request Feb 19, 2021
Unlike other features built on Attribute API, reserved options for
`enum` has leading `_`.

* `_prefix`/`_suffix`: rails#19813, rails#20999
* `_scopes`: rails#34605
* `_default`: rails#39820

That is due to `enum` takes one hash argument only, which contains both
enum definitions and reserved options.

I propose new syntax for `enum` to avoid leading `_` from reserved
options, by allowing `enum(attr_name, ..., **options)` more Attribute
API like syntax.

Before:

```ruby
class Book < ActiveRecord::Base
  enum status: [ :proposed, :written ], _prefix: true, _scopes: false
  enum cover: [ :hard, :soft ], _suffix: true, _default: :hard
end
```

After:

```ruby
class Book < ActiveRecord::Base
  enum :status, [ :proposed, :written ], prefix: true, scopes: false
  enum :cover, [ :hard, :soft ], suffix: true, default: :hard
end
```
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

Successfully merging this pull request may close these issues.

3 participants