class CC::Resolv

Public Class Methods

with_fixed_dns(dns = ::Resolv::DNS.new) { || ... } click to toggle source
# File lib/cc/resolv.rb, line 5
def self.with_fixed_dns(dns = ::Resolv::DNS.new)
  ::Resolv::DefaultResolver.replace_resolvers([Fixed.new(dns)])

  yield if block_given?
ensure
  # There's no way to ask what the current values are before we override
  # them; hopefully going by the source is good enough.
  # https://docs.ruby-lang.org/en/2.0.0/Resolv.html#method-c-new
  default_resolvers = [::Resolv::Hosts.new, ::Resolv::DNS.new]
  ::Resolv::DefaultResolver.replace_resolvers(default_resolvers)
end