-
Notifications
You must be signed in to change notification settings - Fork 2.2k
(PUP-11552) Pass ERB arguments as keywords #8918
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
Conversation
Can one of the admins verify this patch? |
13dc484
to
fd44792
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was unsure about a convention for '
vs "
in the codebase. It looks like it's often "
but not always.
55d11e0
to
c4ce7ef
Compare
This is now green. It avoids warnings on Ruby 3.1, which in itself isn't in CI, but since Ruby 2.5 - 3.0 is tested all branches should be covered. |
Thanks @ekohl! My only concern is whether we're calling if RUBY_VERSION >= "2.7"
def create_erb(content)
ERB.new(content, trim_mode: '-')
end
else
def self.create_erb(content)
ERB.new(content, 0, "-")
end
end
module_function :create_erb And then just call that method, passing in the ERB content: Puppet::Util.create_erb(Puppet::FileSystem.read(@file, :encoding => 'utf-8'))
|
Oh, that's more elegant. Until now I've often modified scripts rather than long running daemons. I also discovered the |
7021b5f
to
cac7347
Compare
Ruby 2.6 introduced trim_mode as a keyword argument and deprecated the use of safe_level as well as calling it as positional arguments. On Ruby 3.1 calling it as a non-keyword argument raises a deprecation warning. warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments. warning: Passing trim_mode with the 3rd argument of ERB.new is deprecated. Use keyword argument like ERB.new(str, trim_mode: ...) instead.
cac7347
to
9938cd8
Compare
And it's green now. |
@joshcooper mind taking another look? |
Thanks for your contribution @ekohl! I verified this fixes all of the ERB keyword test failures on Ruby 3.1. There are a few unrelated failures that should be resolved once we start on this epic https://tickets.puppetlabs.com/browse/PUP-11544 |
Which ones? I run Puppet on Ruby 3.1 and haven't seen them. On the Facter side I opened puppetlabs/facter#2496 but didn't see any on the Puppet side. |
Ah sorry I mean there are still some failures when running puppet rspec tests, which should get fixed in https://tickets.puppetlabs.com/browse/PUP-11406 |
Ah, sounds like errors in the test suite which you don't notice at runtime. Still, looking forward to official Ruby 3.1 support. |
On Ruby 3.1 passing the arguments as positional arguments raises warnings:
However, on Ruby < 2.7 passing as keyword arguments is not allowed. This is why a conditional with RUBY_VERSION is used.
I must admit I have not tested my changes yet and am relying on CI to tell me now.