Replace the DNS resolver.
gem install resolver_replace
Ruby comes with a pure Ruby replacement, resolv-replace. It replaces the libc resolver with the built-in Resolv class which is a thread-aware DNS resolver library.
This gem works similarly, but allows to replace the resolver with your favorite resolver.
For example, if you want to replace the resolver with Resolv::DNS
, write as followings:
require 'resolv' # Resolv::DNS
require 'resolver_replace' # ResolverReplace
resolver = Resolv::DNS.new(:nameserver => ['210.251.121.21'],
:search => ['ruby-lang.org'],
:ndots => 1)
ResolverReplace.register!(
getaddress: Proc.new {|host| resolver.getaddress(host) },
getaddresses: Proc.new {|host| resolver.getaddresses(host) },
error_class: Resolv::ResolvError,
)
Some gems like mysql2
implement its connection in its C extension without using ruby library.
In such case, another monkeypatch must be applied. A plugin scheme of ResolveReplace is ready for such case.
The mysql2
plugin is available for example. Use as followings:
ResolverReplace.load_plugin('mysql2')
ResolverReplace.register!(
getaddress: Proc.new {|host| resolver.getaddress(host) },
getaddresses: Proc.new {|host| resolver.getaddresses(host) },
error_class: Resolv::ResolvError,
)
See CHANGELOG.md for details.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Copyright (c) 2014 Naotoshi Seo. See LICENSE.txt for details.