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 #297

Merged

Conversation

koic
Copy link
Contributor

@koic koic commented May 6, 2018

This PR suppresses the following warnings.

bundle exec rake
/Users/koic/src/github.com/voormedia/rails-erd/lib/rails_erd/diagram/graphviz.rb:313:
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/voormedia/rails-erd/lib/rails_erd/diagram/graphviz.rb:313:
warning: Passing trim_mode with the 3rd argument of ERB.new is
deprecated. Use keyword argument like ERB.new(str, trim_mode: ...) instead.

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/2311087/NEWS#stdlib-updates-outstanding-ones-only

@kerrizor kerrizor self-assigned this May 6, 2018
@koic koic force-pushed the deprecate_safe_level_of_erb_new_in_ruby_2_6 branch from 98e584d to d9999a0 Compare May 11, 2018 08:06
@kerrizor
Copy link
Collaborator

Hi, and thanks for the PR! Apologies on not responding sooner; my workflow for being notified of new issues broke such that I received some notifications, but not all, and unfortunately yours was one I missed.

If you have the time, could you rebase and resubmit? I recently merged fixes for minitest that may help clear up your test failures.

This PR suppresses the following warnings.

```console
bundle exec rake
/Users/koic/src/github.com/voormedia/rails-erd/lib/rails_erd/diagram/graphviz.rb:313:
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/voormedia/rails-erd/lib/rails_erd/diagram/graphviz.rb:313:
warning: Passing trim_mode with the 3rd argument of ERB.new is
deprecated. Use keyword argument like ERB.new(str, trim_mode: ...) instead.
```

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/2311087/NEWS#stdlib-updates-outstanding-ones-only
@koic koic force-pushed the deprecate_safe_level_of_erb_new_in_ruby_2_6 branch from d9999a0 to 11b3fff Compare December 13, 2018 07:42
@koic
Copy link
Contributor Author

koic commented Dec 13, 2018

@kerrizor I rebased this PR. Thanks for the replying!

@@ -310,7 +310,12 @@ def specialization_options(specialization)
end

def read_template(type)
ERB.new(File.read(File.expand_path("templates/#{NODE_LABEL_TEMPLATES[type]}", File.dirname(__FILE__))), nil, "<>")
template_text = File.read(File.expand_path("templates/#{NODE_LABEL_TEMPLATES[type]}", File.dirname(__FILE__)))
if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't it be easier and clearer to just use the RUBY_VERSION constant instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR uses ERB.instance_method(:initialize).parameters.assoc(:key) instead of RUBY_VERSION of ERB.new. This approach is built into Ruby.
ruby/ruby@3406c5d

@kerrizor kerrizor merged commit 3d4fdf3 into voormedia:master May 10, 2019
@kerrizor
Copy link
Collaborator

Thanks again, @koic

@koic koic deleted the deprecate_safe_level_of_erb_new_in_ruby_2_6 branch May 11, 2019 02:32
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

3 participants