Skip to content

Commit b2c775c

Browse files
committed
Require win32/resolv just once
And Use Win32::Resolv instead of a constant `WINDOWS`.
1 parent 60bf151 commit b2c775c

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

lib/resolv.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,21 +174,18 @@ class ResolvError < StandardError; end
174174

175175
class ResolvTimeout < Timeout::Error; end
176176

177-
WINDOWS = /mswin|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM || ::RbConfig::CONFIG['host_os'] =~ /mswin/
178-
private_constant :WINDOWS
179-
180177
##
181178
# Resolv::Hosts is a hostname resolver that uses the system hosts file.
182179

183180
class Hosts
184-
if WINDOWS
181+
if /mswin|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM || ::RbConfig::CONFIG['host_os'] =~ /mswin/
185182
begin
186183
require 'win32/resolv' unless defined?(Win32::Resolv)
187-
DefaultFileName = Win32::Resolv.get_hosts_path || IO::NULL
184+
hosts = Win32::Resolv.get_hosts_path || IO::NULL
188185
rescue LoadError
189186
end
190187
end
191-
DefaultFileName ||= '/etc/hosts'
188+
DefaultFileName = hosts || '/etc/hosts'
192189

193190
##
194191
# Creates a new Resolv::Hosts, using +filename+ for its data source.
@@ -1022,8 +1019,7 @@ def Config.parse_resolv_conf(filename)
10221019
def Config.default_config_hash(filename="/etc/resolv.conf")
10231020
if File.exist? filename
10241021
Config.parse_resolv_conf(filename)
1025-
elsif WINDOWS
1026-
require 'win32/resolv' unless defined?(Win32::Resolv)
1022+
elsif defined?(Win32::Resolv)
10271023
search, nameserver = Win32::Resolv.get_resolv_info
10281024
config_hash = {}
10291025
config_hash[:nameserver] = nameserver if nameserver

0 commit comments

Comments
 (0)