Skip to content

Commit 4836dd0

Browse files
committed
(maint) Simplifies SSLContext intialization
Ruby 2.5 added the `keyword_init: true` option to Struct.new to enable keyword arguments. This commit updates the Puppet::SSL::SSLContext to take advantage of this language feature and removes a workaround needed for older versions of Ruby. Additionally, Ruby 3.2 addeed the ability to initialize a Struct with keyword arguments without the `keyword_init: true` option. This commit adds a comment noting that, so it can be removed in the future when Puppet drops support for Ruby < 3.2.
1 parent fd7f09f commit 4836dd0

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

lib/puppet/ssl/ssl_context.rb

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
require_relative '../../puppet/ssl'
22

33
module Puppet::SSL
4+
# Struct in Ruby >= 2.5 uses the `keyword_init: true` option to allow for keyword arguments. Ruby >= 3.2 allows Struct.new to use keyword
5+
# arguments without `keyword_init: true`
46
SSLContext = Struct.new(
57
:store,
68
:cacerts,
@@ -9,22 +11,18 @@ module Puppet::SSL
911
:client_cert,
1012
:client_chain,
1113
:revocation,
12-
:verify_peer
13-
) do
14-
DEFAULTS = {
14+
:verify_peer,
15+
keyword_init: true
16+
)
17+
18+
# Initialize with default values
19+
def initialize
20+
SSLContext.new(
1521
cacerts: [],
1622
crls: [],
1723
client_chain: [],
1824
revocation: true,
1925
verify_peer: true
20-
}.freeze
21-
22-
# This is an idiom to initialize a Struct from keyword
23-
# arguments. Ruby 2.5 introduced `keyword_init: true` for
24-
# that purpose, but we need to support older versions.
25-
def initialize(kwargs = {})
26-
super({})
27-
DEFAULTS.merge(**kwargs).each { |k,v| self[k] = v }
28-
end
26+
)
2927
end
3028
end

0 commit comments

Comments
 (0)