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

Support Rails7 style enum definitions #268

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tk0miya
Copy link
Collaborator

@tk0miya tk0miya commented Aug 15, 2023

Since Rails7, the enum definition style has been changed. This uses a private a private method #_enum_methods_module to obtain the registered enum defintions to support both Rails5 and Rails7.

Thanks to @ksss. (refs: #6)

This is yet another version of #267 (static analytics approach).

  • Pros
    • Very simple code
  • Cons
    • Touch the internal of the Enum system

tk0miya added a commit to tk0miya/conference-app that referenced this pull request Nov 6, 2023
As a preparation of giving types to controllers, this adds types for
`Announcement::ActiveRecord_Relation#published` manually because
current rbs_rails does not support Rails7 style enums. It should be
removed if rbs_rails will support it in the future.

refs: pocke/rbs_rails#268
@tk0miya
Copy link
Collaborator Author

tk0miya commented Feb 12, 2024

Now rebased on #274 .

@derikson
Copy link

derikson commented Mar 6, 2024

Unfortunately, this approach doesn't work when instance_methods: false in the enum options. However, I think it's preferable to parsing both the old definition style and the new definition style, and it handles enums defined outside the model file.

Since Rails7, the enum definition style has been changed.  This uses a
private a private method `#_enum_methods_module` to obtain the
registered enum defintions to support both Rails5 and Rails7.

Thanks to @ksss.
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.

2 participants