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

Make core extensions cleaner with refinements #709

Merged
merged 2 commits into from
Aug 11, 2024

Conversation

amatsuda
Copy link
Contributor

This gem monkey-patches Object class and String class with the following four methods for the gem internal use,

Object#bullet_key
Object#bullet_primary_key_value
Object#bullet_join_potential_composite_primary_key
String#bullet_class_name

and these methods are globally polluting every Object in the whole Ruby process.

This kind of monkey-patching is a dangerous approach and should be avoided in a gem that is usually bundled only in development/test, since it may become a cause of weird bugs that happen only on production env.

So, here's a patch that encapsulates these monkey-patches inside this gem by rewriting the core-exts to use refinements.

Note that this can be an incompatible change for those who use these methods from their application code. I can hardly imagine such a use case, but in such case, they may have to add using calls to their application.

@amatsuda amatsuda force-pushed the refine branch 2 times, most recently from 9fecd15 to 5a0286e Compare July 23, 2024 08:40
@@ -21,11 +23,11 @@ def add_possible_objects(object_or_objects)
return unless Bullet.counter_cache_enable?

objects = Array.wrap(object_or_objects)
return if objects.map(&:bullet_primary_key_value).compact.empty?
return if objects.map { |object| object.bullet_primary_key_value }.compact.empty?
Copy link
Owner

Choose a reason for hiding this comment

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

@amatsuda what's the reason to make this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's described in the third commit 5a0286e
We don't need this change if we could drop Ruby 2.3 support.

@flyerhzm
Copy link
Owner

@amatsuda #713 is merged, please rebase the main branch to make CI happy.

@amatsuda
Copy link
Contributor Author

@flyerhzm Rebased!

@flyerhzm flyerhzm merged commit f39bf9a into flyerhzm:main Aug 11, 2024
9 checks passed
@amatsuda amatsuda deleted the refine branch August 15, 2024 15:24
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