Skip to content

Commit

Permalink
Fix ERB deprecation warning (#360)
Browse files Browse the repository at this point in the history
* Fix ERB deprecation warning

example warning:
```
lib/generators/scenic/model/model_generator.rb:39: warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments.
```

followed Ruby standard library style to make distinction on ERB version check:
ruby/ruby@3406c5d
  • Loading branch information
aliismayilov authored Apr 25, 2022
1 parent 1ffb3cd commit 5801335
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/generators/scenic/model/model_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,23 @@ def invoke_view_generator
def evaluate_template(source)
source = File.expand_path(find_in_source_paths(source.to_s))
context = instance_eval("binding", __FILE__, __LINE__)
ERB.new(
::File.binread(source),
nil,
"-",
"@output_buffer",
).result(context)

if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
erb = ERB.new(
::File.binread(source),
trim_mode: "-",
eoutvar: "@output_buffer",
)
else
erb = ERB.new(
::File.binread(source),
nil,
"-",
"@output_buffer",
)
end

erb.result(context)
end

def generating?
Expand Down

0 comments on commit 5801335

Please sign in to comment.