8000 Return value of `enum` so it remains compatible with other enum extensions (e.g. stateful_enum) by kiyo-e · Pull Request #52 · zmbacker/enum_help · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Return value of enum so it remains compatible with other enum extensions (e.g. stateful_enum) #52

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

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

Conversation

kiyo-e
94FA
Copy link
@kiyo-e kiyo-e commented May 1, 2025

What does this PR do?

EnumHelp::I18n re-defines ActiveRecord::Base#enum but did not return the
value from super.
When another gem (notably stateful_enum) wraps enum and expects the
original Hash definition to be returned, the call chain receives nil (or a
Symbol) and crashes with:

NoMethodError: undefined method `map' for nil:NilClass
    .../stateful_enum/machine.rb:8:in `initialize'

This PR stores the result of super, executes EnumHelp’s I18n helpers, and
finally returns the original result object.
No other behaviour is changed.


Why is it needed?

  • Allows enum_help to coexist with popular gems that decorate enum
    (stateful_enum etc.).
  • Removes the need for ad-hoc monkey-patches in downstream applications.

Implementation details

definitions = super           # call the next #enum implementation
                         # existing i18n helper definitions
definitions                    # ← **return it**

No other lines were modified.


Backwards compatibility

  • The change only affects the return value; public APIs and generated I18n
    helper methods are untouched.

Thank you for reviewing! Please let me know if further changes are required.

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.

1 participant
0