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

Add skip-collision-check option to generator #36603

Merged
merged 1 commit into from Jul 17, 2019

Conversation

@y-yagi
Copy link
Member

@y-yagi y-yagi commented Jul 5, 2019

Until Rails 5.2, generators can run same name multi times without destroying.
But Rails 6.0(with Zeitwerk) can't this. In Rails 6.0, an error occurs due to class name collision check.

The check uses const_defined?, which assumes that the autoload object
is also defined.
https://ruby-doc.org/core-2.6.3/Module.html#method-i-const_defined-3F

It did not work until Rails 5.2, but Zeitwerk seems to be able to correctly check this against the application's code.

However, this is a little inconvenient if want to run the generator again like mistake an attribute name(need to run destoy before).
In order to solve this, this PR adds an option to skip the collision check. With this option, can overwrite files just as did until Rails 5.2.

Until Rails 5.2, generators can run same name multi times without destroying.
But Rails 6.0(with Zeitwerk) can't this. In Rails 6.0, an error occurs
due to class name collision check.

The check uses `const_defined?`, which assumes that the autoload object
is also defined.
https://ruby-doc.org/core-2.6.3/Module.html#method-i-const_defined-3F

It did not work until Rails 5.2, but Zeitwerk seems to be able to
correctly check this against the application's code.

However, this is a little inconvenient if want to run the generator
again like mistake an attribute name(need to run `destoy` before).

In order to solve this, this PR adds an option to skip the collision check.
With this option, you can overwrite files just as did until Rails 5.2.
@rails-bot rails-bot bot added the railties label Jul 5, 2019
@y-yagi y-yagi merged commit c5a24c8 into rails:master Jul 17, 2019
2 checks passed
Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

1 participant