Skip to content

Commit ccaf072

Browse files
committed
Allow setting default Resolv::DNS config in Resolv.new
Instead of just passing the use_ipv6 option, pass all options given. By using a singular hash argument instead of keywords, this avoids the issue when a user does: ```ruby Resolv.new([Resolv::DNS.new], use_ipv6: false) ``` Which would have resulted in the use_ipv6 option being ignored. This is backwards compatible, because there has not yet been a release with the use_ipv6 keyword supported.
1 parent c0e5aba commit ccaf072

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/resolv.rb

+12-3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,18 @@ def self.each_name(address, &proc)
8383

8484
##
8585
# Creates a new Resolv using +resolvers+.
86-
87-
def initialize(resolvers=nil, use_ipv6: nil)
88-
@resolvers = resolvers || [Hosts.new, DNS.new(DNS::Config.default_config_hash.merge(use_ipv6: use_ipv6))]
86+
#
87+
# If +resolvers+ is not given, a hash, or +nil+, uses a Hosts resolver and
88+
# and a DNS resolver. If +resolvers+ is a hash, uses the hash as
89+
# configuration for the DNS resolver.
90+
91+
def initialize(resolvers=nil)
92+
@resolvers = case resolvers
93+
when Hash, nil
94+
[Hosts.new, DNS.new(DNS::Config.default_config_hash.merge(resolvers || {}))]
95+
else
96+
resolvers
97+
end
8998
end
9099

91100
##

0 commit comments

Comments
 (0)