Class: EventMachine::DNS::Resolver
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/em/resolver.rb |
Constant Summary
-
HOSTS_FILE =
# File 'lib/em/resolver.rb', line 14windows? ? Win32::Resolv.get_hosts_path : '/etc/hosts'
Class Attribute Summary
- .nameservers rw
- .nameservers=(ns) rw
- .windows? ⇒ Boolean readonly
Class Method Summary
Class Attribute Details
.nameservers (rw)
[ GitHub ]# File 'lib/em/resolver.rb', line 36
def self.nameservers return @nameservers if @nameservers if windows? _, ns = Win32::Resolv.get_resolv_info return @nameservers = ns || [] end @nameservers = [] IO.readlines('/etc/resolv.conf').each do |line| if line =~ /^nameserver (.+)$/ @nameservers << $1.split(/\s+/).first end end @nameservers rescue @nameservers = [] end
.nameservers=(ns) (rw)
[ GitHub ]# File 'lib/em/resolver.rb', line 32
def self.nameservers=(ns) @nameservers = ns end
.windows? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/em/resolver.rb', line 5
def self.windows? if RUBY_PLATFORM =~ /mswin32|cygwin|mingw|bccwin/ require 'win32/resolv' true else false end end
Class Method Details
.hosts
[ GitHub ]# File 'lib/em/resolver.rb', line 60
def self.hosts return @hosts if @hosts @hosts = {} IO.readlines(HOSTS_FILE).each do |line| next if line =~ /^#/ addr, host = line.split(/\s+/) next unless addr && host @hosts[host] ||= [] @hosts[host] << addr end @hosts rescue @hosts = {} end
.nameserver
[ GitHub ]# File 'lib/em/resolver.rb', line 56
def self.nameserver nameservers.shuffle.first end