Skip to content
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

Allow setting default Resolv::DNS config in Resolv.new #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/resolv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,22 @@ def self.each_name(address, &proc)

##
# Creates a new Resolv using +resolvers+.
#
# If +resolvers+ is not given, a hash, or +nil+, uses a Hosts resolver and
# and a DNS resolver. If +resolvers+ is a hash, uses the hash as
# configuration for the DNS resolver.

def initialize(resolvers=(arg_not_set = true; nil), use_ipv6: (keyword_not_set = true; nil))
if !keyword_not_set && !arg_not_set
warn "Support for separate use_ipv6 keyword is deprecated, as it is ignored if an argument is provided. Do not provide a positional argument if using the use_ipv6 keyword argument.", uplevel: 1
end

def initialize(resolvers=nil, use_ipv6: nil)
@resolvers = resolvers || [Hosts.new, DNS.new(DNS::Config.default_config_hash.merge(use_ipv6: use_ipv6))]
@resolvers = case resolvers
when Hash, nil
[Hosts.new, DNS.new(DNS::Config.default_config_hash.merge(resolvers || {}))]
else
resolvers
end
end

##
Expand Down