Skip to content

Commit

Permalink
Get rid of ERB warning for Ruby 2.6+
Browse files Browse the repository at this point in the history
Signed-off-by: Takashi Kokubun <[email protected]>
  • Loading branch information
k0kubun committed May 31, 2019
1 parent 241a37f commit a1902f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
16 changes: 14 additions & 2 deletions lib/fluent/command/plugin_config_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,27 @@ def dump_section_markdown(base_section, level = 0)
params.each do |name, config|
next if name == :section
template_name = @compact ? "param.md-compact.erb" : "param.md.erb"
dumped << ERB.new(template_path(template_name).read, nil, "-").result(binding)
template = template_path(template_name).read
dumped <<
if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
ERB.new(template, trim_mode: "-")
else
ERB.new(template, nil, "-")
end.result(binding)
end
dumped << "\n"
sections.each do |section_name, sub_section|
required = sub_section.delete(:required)
multi = sub_section.delete(:multi)
alias_name = sub_section.delete(:alias)
sub_section.delete(:section)
dumped << ERB.new(template_path("section.md.erb").read, nil, "-").result(binding)
template = template_path("section.md.erb").read
dumped <<
if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
ERB.new(template, trim_mode: "-")
else
ERB.new(template, nil, "-")
end.result(binding)
end
dumped
end
Expand Down
7 changes: 6 additions & 1 deletion lib/fluent/command/plugin_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ def template_file(filename)

def template(source, dest)
dest.dirname.mkpath
contents = ERB.new(source.read, nil, "-").result(binding)
contents =
if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
ERB.new(source.read, trim_mode: "-")
else
ERB.new(source.read, nil, "-")
end.result(binding)
label = create_label(dest, contents)
puts "\t#{label} #{dest}"
if label == "conflict"
Expand Down

0 comments on commit a1902f3

Please sign in to comment.