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

Create dedicated Attrable mixin for attr_ methods #16406

Merged
merged 2 commits into from Jan 1, 2024

Conversation

dduugg
Copy link
Sponsor Member

@dduugg dduugg commented Dec 28, 2023

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

attr_rw was monkey-patched into Module, polluting every namespace, despite being used in only three modules. This PR yanks it into a dedicated mixin, Attrable. I also moved in attr_predicate, bc it seemed like overkill to have a mixin for each. Finally, I stopped including them from global, and required them only in the files where they are used.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Looks good, good idea @dduugg. One chance for a cleanup, if possible (but might not me).

sig { params(attrs: Symbol).void }
def attr_rw(*attrs)
attrs.each do |attr|
module_eval <<-EOS, __FILE__, __LINE__+1
Copy link
Member

Choose a reason for hiding this comment

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

Can this be done with define_method?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Done! (I simplified it as well, taking advantage of instance_variable_get returning nil for unset ivars.)

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Looks good, lovely cleanup, thanks @dduugg!

@MikeMcQuaid MikeMcQuaid merged commit 705d256 into Homebrew:master Jan 1, 2024
24 checks passed
@dduugg dduugg deleted the attrable branch January 5, 2024 00:54
@dduugg dduugg restored the attrable branch January 5, 2024 00:54
@dduugg dduugg deleted the attrable branch January 5, 2024 00:54
@github-actions github-actions bot added the outdated PR was locked due to age label Feb 5, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants