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

Deprecate safe_level of ERB.new in Ruby 2.6 #32170

Merged

Conversation

koic
Copy link
Contributor

@koic koic commented Mar 5, 2018

Summary

In a Rails application using Ruby 2.6.0-dev, when running bin/rails g migration with RUBYOPT=-w, an ERB deprecation warnings will be displayed.

% ruby -v
ruby 2.6.0dev (2018-03-03 trunk 62644) [x86_64-darwin17]
% bin/rails -v
Rails 6.0.0.alpha
% RUBYOPT=-w bin/rails g migration create_foos

(snip)

/Users/koic/src/github.com/rails/rails/railties/lib/rails/generators/migration.rb:66:
warning: Passing safe_level with the 2nd argument of ERB.new is
deprecated. Do not use it, and specify other arguments as keyword
arguments.
/Users/koic/src/github.com/rails/rails/railties/lib/rails/generators/migration.rb:66:
warning: Passing trim_mode with the 3rd argument of ERB.new is
deprecated. Use keyword argument like ERB.new(str, trim_mode: ...)
instead.
/Users/koic/src/github.com/rails/rails/railties/lib/rails/generators/migration.rb:66:
warning: Passing eoutvar with the 4th argument of ERB.new is
deprecated. Use keyword argument like ERB.new(str, eoutvar: ...)
instead.
      create    db/migrate/20180304002144_create_foos.rb

This PR suppresses the above deprecation warnings in Ruby 2.6.0-dev.

This warning is due to the interface of ERB.new will change from Ruby 2.6.

Add :trim_mode and :eoutvar keyword arguments to ERB.new.
Now non-keyword arguments other than first one are softly deprecated
and will be removed when Ruby 2.5 becomes EOL. [Feature #14256]

https://github.com/ruby/ruby/blob/2311087b685e8dc0f21f4a89875f25c22f5c39a9/NEWS#stdlib-updates-outstanding-ones-only

The following addresses are related Ruby's commit.
ruby/ruby@cc777d0

Also this PR will change ERB.new used in tasks/release.rb.

Other Information

This PR uses ERB.version to switch ERB.new interface. Because Rails 6 supports multiple Ruby versions (Ruby 2.4.1 or higher), it need to use the appropriate interface.

Using ERB.version instead of RUBY_VERSON is based on the following patch.
ruby/ruby#1826

This patch is built into Ruby.
ruby/ruby@40db89c

@rails-bot
Copy link

r? @pixeltrix

(@rails-bot has picked a reviewer for you, use r? to override)

@@ -63,7 +63,12 @@ def migration_template(source, destination, config = {})
numbered_destination = File.join(dir, ["%migration_number%", base].join("_"))

create_migration numbered_destination, nil, config do
ERB.new(::File.binread(source), nil, "-", "@output_buffer").result(context)
match = ERB.version.match(/\Aerb\.rb \[(?<version>[^ ]+) /)
if match && match[:version] >= '2.2.0' # Ruby 2.6+
Copy link
Member

Choose a reason for hiding this comment

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

Use double quotes.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made a basic error 💦 I fixed it.

tasks/release.rb Outdated
puts ERB.new(template, nil, "<>").result(binding)

match = ERB.version.match(/\Aerb\.rb \[(?<version>[^ ]+) /)
if match && match[:version] >= '2.2.0' # Ruby 2.6+
Copy link
Member

Choose a reason for hiding this comment

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

ditto.

### Summary

In a Rails application using Ruby 2.6.0-dev, when running `bin/rails g migration`
with `RUBYOPT=-w`, an ERB deprecation warnings will be displayed.

```console
% ruby -v
ruby 2.6.0dev (2018-03-03 trunk 62644) [x86_64-darwin17]
% bin/rails -v
Rails 6.0.0.alpha
% RUBYOPT=-w bin/rails g migration create_foos

(snip)

/Users/koic/src/github.com/rails/rails/railties/lib/rails/generators/migration.rb:66:
warning: Passing safe_level with the 2nd argument of ERB.new is
deprecated. Do not use it, and specify other arguments as keyword
arguments.
/Users/koic/src/github.com/rails/rails/railties/lib/rails/generators/migration.rb:66:
warning: Passing trim_mode with the 3rd argument of ERB.new is
deprecated. Use keyword argument like ERB.new(str, trim_mode: ...)
instead.
/Users/koic/src/github.com/rails/rails/railties/lib/rails/generators/migration.rb:66:
warning: Passing eoutvar with the 4th argument of ERB.new is
deprecated. Use keyword argument like ERB.new(str, eoutvar: ...)
instead.
      create    db/migrate/20180304002144_create_foos.rb
```

This PR suppresses the above deprecation warnings in Ruby 2.6.0-dev.

This warning is due to the interface of `ERB.new` will change from Ruby 2.6.

> Add :trim_mode and :eoutvar keyword arguments to ERB.new.
> Now non-keyword arguments other than first one are softly deprecated
> and will be removed when Ruby 2.5 becomes EOL. [Feature rails#14256]

https://github.com/ruby/ruby/blob/2311087b685e8dc0f21f4a89875f25c22f5c39a9/NEWS#stdlib-updates-outstanding-ones-only

The following addresses are related Ruby's commit.
ruby/ruby@cc777d0

Also this PR will change `ERB.new` used in `tasks/release.rb`.

### Other Information

This PR uses `ERB.version` to switch `ERB.new` interface. Because Rails 6
supports multiple Ruby versions (Ruby 2.4.1 or higher), it need to
use the appropriate interface.

Using `ERB.version` instead of `RUBY_VERSON` is based on the following patch.
ruby/ruby#1826

This patch is built into Ruby.
ruby/ruby@40db89c
@koic koic force-pushed the deprecate_safe_level_of_erb_new_in_ruby_2_6 branch from b70f5cd to e8be4f0 Compare March 5, 2018 09:51
@kamipo kamipo merged commit d13ce1f into rails:master Mar 5, 2018
@koic koic deleted the deprecate_safe_level_of_erb_new_in_ruby_2_6 branch March 5, 2018 12:20
kamipo added a commit that referenced this pull request Mar 5, 2018
…n_ruby_2_6

Deprecate safe_level of `ERB.new` in Ruby 2.6
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

4 participants