Skip to content

Commit 70021d0

Browse files
committed
Deprecate safe_level of ERB.new in Ruby 2.6
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 address is related Ruby's commit. ruby/ruby@cc777d0 This PR uses `ERB.version` to switch `ERB.new` interface. Because Thor supports multiple Ruby versions, 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
1 parent 0e2615f commit 70021d0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/thor/actions/file_manipulation.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,13 @@ def template(source, *args, &block)
117117
context = config.delete(:context) || instance_eval("binding")
118118

119119
create_file destination, nil, config do
120-
content = CapturableERB.new(::File.binread(source), nil, "-", "@output_buffer").tap do |erb|
120+
match = ERB.version.match(/(\d\.\d\.\d)/)
121+
capturable_erb = if match && match[1] >= "2.2.0" # Ruby 2.6+
122+
CapturableERB.new(::File.binread(source), :trim_mode => "-", :eoutvar => "@output_buffer")
123+
else
124+
CapturableERB.new(::File.binread(source), nil, "-", "@output_buffer")
125+
end
126+
content = capturable_erb.tap do |erb|
121127
erb.filename = source
122128
end.result(context)
123129
content = yield(content) if block

0 commit comments

Comments
 (0)