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

Use dup'ed options hash #31641

Merged
merged 1 commit into from Jan 20, 2018
Merged

Conversation

ckoenig
Copy link
Contributor

@ckoenig ckoenig commented Jan 5, 2018

Otherwise, at least using JRuby, the replacements in convert_database_option_for_jruby won't work. Thus a call to

bundle exec rails app:update

fails. Simply replacing those replace statements doesn't seem to work either, since the options hash seems to be frozen, too.

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @georgeclaghorn (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@y-yagi
Copy link
Member

y-yagi commented Jan 7, 2018

We want to keep frozen_string_literal.
How about to dup options instead of removing frozen_string_literal?

diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb
index 400f954..4176bb4 100644
--- a/railties/lib/rails/generators/app_base.rb
+++ b/railties/lib/rails/generators/app_base.rb
@@ -315,11 +315,14 @@ def gem_for_database
 
       def convert_database_option_for_jruby
         if defined?(JRUBY_VERSION)
-          case options[:database]
-          when "postgresql" then options[:database].replace "jdbcpostgresql"
-          when "mysql"      then options[:database].replace "jdbcmysql"
-          when "sqlite3"    then options[:database].replace "jdbcsqlite3"
+          opt = options.dup
+          case opt[:database]
+          when "postgresql" then opt[:database] = "jdbcpostgresql"
+          when "mysql"      then opt[:database] = "jdbcmysql"
+          when "sqlite3"    then opt[:database] = "jdbcsqlite3"
           end
+
+          self.options = opt
         end 

@matthewd
Copy link
Member

matthewd commented Jan 7, 2018

I don't think it even needs to duplicate options; seems that it can safely update the existing options directly, just switching from replace to =.

@y-yagi
Copy link
Member

y-yagi commented Jan 7, 2018

options is a frozen object.
So without dup, will raise RuntimeError(can't modify frozen Thor::CoreExt::HashWithIndifferentAccess).
Ref: rails/thor#446

@matthewd
Copy link
Member

matthewd commented Jan 7, 2018

Ah, right 👍

@ckoenig
Copy link
Contributor Author

ckoenig commented Jan 8, 2018

I changed my PR based on @y-yagi's proposal. Only difference is, that I'm freezing the options again.

@y-yagi
Copy link
Member

y-yagi commented Jan 8, 2018

LGTM. Please squash your commits into a single commit?

Otherwise, at least using JRuby, the replacements in
convert_database_option_for_jruby won't work. Thus a call to

    bundle exec rails app:update

fails. Simply replacing those replace statements doesn't seem to work
either, since the options hash seems to be frozen, too.
@ckoenig ckoenig force-pushed the remove_frozen_string_literal branch from 129b9d8 to c33f47d Compare January 9, 2018 08:15
@ckoenig ckoenig changed the title Remove frozen_string_literal from generator Use dup'ed options hash Jan 9, 2018
@y-yagi y-yagi merged commit 9bf41f2 into rails:master Jan 20, 2018
@y-yagi
Copy link
Member

y-yagi commented Jan 20, 2018

@ckoenig Thanks!

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.

None yet

5 participants