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

Move bundle_report rails compatibility logic into a class #137

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JuanVqz
Copy link
Member

@JuanVqz JuanVqz commented Feb 11, 2025

Description

I extracted it into its own class

Motivation and Context

I think it will be easier to understand the BundleReport.compatibility method and its usage
also I will need to use data from the incompatible_gems_by_state method in another code.

How Has This Been Tested?

There was an existing test case for the erb_output method, and I run it locally to make sure it still works.

Screenshots:

I will abide by the code of conduct


incompatible_gems.each { |gem| gem.find_latest_compatible(rails_version: rails_version) }
Copy link
Member Author

@JuanVqz JuanVqz Feb 11, 2025

Choose a reason for hiding this comment

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

@arielj I noticed you wrote this code, could you please elavorate a bit on this line? why is it needed? how is used? I do not get it. Thanks!

Copy link

Choose a reason for hiding this comment

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

incompatible_gems is an array of gems that, given the current version they are in, are not compatible with the desired version of Rails

then this line loops through that array and looks for the newest version of each of those gems that is compatible with the desired version of Rails, that information is stored in the gem object itself https://github.com/fastruby/next_rails/blob/main/lib/next_rails/gem_info.rb#L137 and it's used to print the target version of that gem in line 32

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense, yeah I noticed it was related to finding the latest compatible rails version for the gem, but didn't realize it. thanks! now that I have your attention what do you think about the PR? can you review it please?

@JuanVqz JuanVqz requested review from etagwerker and arielj February 11, 2025 21:15
@JuanVqz JuanVqz force-pushed the move-rails-version-compatibility-into-its-own-class branch 2 times, most recently from 61699bf to 7f7a9df Compare February 11, 2025 22:05
Copy link

@arielj arielj left a comment

Choose a reason for hiding this comment

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

I added some comments

end

def incompatible_gems
@gems.reject { |gem| incompatible?(gem) }.sort_by(&:name)
Copy link

Choose a reason for hiding this comment

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

Suggested change
@gems.reject { |gem| incompatible?(gem) }.sort_by(&:name)
@incompatible_gems ||= @gems.reject { |gem| incompatible?(gem) }.sort_by(&:name)

this method is called twice in incompatible_gems_by_state, this way it won't do all the reject->sort thing twice

@options[:rails_version]
end

def incompatible?(gem)
Copy link

Choose a reason for hiding this comment

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

is this name correct? the method is called incompatible? but internally it calls gem.compatible_with_rails?... so I imagine true means compatible, not incompatible

Copy link

Choose a reason for hiding this comment

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

also, it's used in the incompatible_gems method to reject the compatible ones and keep the incompatible ones

I extracted it into a class because I think it will be easier to use the `incompatible_gems_by_state` data there.
@JuanVqz JuanVqz force-pushed the move-rails-version-compatibility-into-its-own-class branch from b8e927b to 74e4bf6 Compare February 20, 2025 21:11
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