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 Rails 6.1.6.1 #1104

Merged
merged 1 commit into from
Aug 15, 2022
Merged

Support Rails 6.1.6.1 #1104

merged 1 commit into from
Aug 15, 2022

Conversation

stevepolitodesign
Copy link
Contributor

@stevepolitodesign stevepolitodesign commented Aug 5, 2022

This commit does the bare minimum to support Rails 6.1.6.1

Because the gem command is no longer reversible, we decided to override the method by borrowing as much from the existing method. The main difference being that we call append_file instead of gsub_file, so that we can preserve reversibility. However, #1066 provides a more elegant solution.

Closes #1060

@stevepolitodesign stevepolitodesign force-pushed the support_rails_6_1_0 branch 2 times, most recently from c86de29 to 710b7d7 Compare August 8, 2022 11:46
@stevepolitodesign stevepolitodesign changed the title Support Rails 6.1.0 Support Rails 6.1.6.1 Aug 8, 2022
Copy link
Contributor

@mike-burns mike-burns left a comment

Choose a reason for hiding this comment

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

What do you think of adding a #gem method to Generators::Base?

def gem(name, **args)
  append_file "Gemfile", %(\n#{name}, #{args.inspect}\n"
end

(Or something like that.)

@stevepolitodesign stevepolitodesign force-pushed the support_rails_6_1_0 branch 2 times, most recently from 2c9a326 to 7f0329b Compare August 12, 2022 01:12
@stevepolitodesign
Copy link
Contributor Author

@mike-burns that works for me!

I ended up adding the method to the Actions module, since I think any method definition in the Base class cannot accept any arguments since it's seen as a generator method (at least that's what the errors were implying).

I ended up borrowing a lot from the existing method, but let me know if this is overkill.

7f0329b

Copy link
Contributor

@mike-burns mike-burns left a comment

Choose a reason for hiding this comment

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

Nice nice nice.

append_file "Gemfile", %(\ngem "sidekiq"\n)
gem "sidekiq"
Copy link
Contributor

Choose a reason for hiding this comment

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

Beautiful!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was my fault. I was accidentally on main when I pushed that up 🤦.

Is it worth removing that commit before I merge this in?

Also, I wonder if we should enable a branch protection rule to prevent this from happening again?

Copy link
Contributor

Choose a reason for hiding this comment

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

Your choice!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think branch protection would be great! As for the commit, it's small and harmless, so I think we can leave it as-is. This PR makes a change to the same line, and also improves it, so that's good.

Copy link
Contributor

@thiagoa thiagoa left a comment

Choose a reason for hiding this comment

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

Nice job, I'm really excited that we're getting closer to the latest Rails!

str = []
str << indentation
str << "gem #{parts.join(", ")}"
append_file "Gemfile", %(\n#{str.join}\n), verbose: false
Copy link
Contributor

Choose a reason for hiding this comment

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

The original Rails method uses append_file_with_newline. Is that method not reversible while append_file is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

append_file_with_newline calls gsub_file which unfortunately is not reversible.

versions.each do |version|
parts << quote(version)
end
message << " (#{versions.join(", ")})"
Copy link
Contributor

@thiagoa thiagoa Aug 12, 2022

Choose a reason for hiding this comment

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

It looks like message is not being used. In the original method, it is used for logging on this line:

log :gemfile, message

Do you think logging would be valuable? Otherwise, we can delete it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Updated here: d55520a

parts << quote(options) unless options.empty?

str = []
str << indentation
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big deal, but I prefer how it reads in the original method:

    str = "gem #{parts.join(", ")}"
    str = indentation + str

Also, the original method uses in_root, but I suppose that is not necessary here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oddly enough, I was getting failures when I used that implementation, but I'm not totally sure why 🤔

I think this might have also been the result of having run standardrb --fix.

@@ -1,4 +1,5 @@
require "active_job/logging"
require "active_job/log_subscriber"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this also necessary for Rails 6.1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oddly enough, yes. Without it, we get uninitialized constant ActiveJob::Logging::LogSubscriber.

This commit does the bare minimum to support Rails 6.1.6.1

Because the `gem` command is no longer reversible, we decided to override the
method by borrowing as much from the [existing
method](https://github.com/rails/rails/blob/04972d9b9ef60796dc8f0917817b5392d61fcf09/railties/lib/rails/generators/actions.rb#L22).
The main difference being that we call `append_file` instead of `gsub_file`, so
that we can preserve reversibility. However, #1066 provides a more elegant
solution.

Closes #1060
@stevepolitodesign stevepolitodesign merged commit 52f9787 into main Aug 15, 2022
@stevepolitodesign stevepolitodesign deleted the support_rails_6_1_0 branch August 15, 2022 14:15
This was referenced Aug 15, 2022
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.

Update for Rails 6.1.0
3 participants