lib/rubydns/resolver.rb in rubydns-0.5.1 vs lib/rubydns/resolver.rb in rubydns-0.5.2

- old
+ new

@@ -50,9 +50,24 @@ message.add_question name, resource_class Request.fetch(message, @servers, @options, &block) end + # Yields a list of `Resolv::IPv4` and `Resolv::IPv6` addresses for the given `name` and `resource_class`. + def addresses_for(name, resource_class = Resolv::DNS::Resource::IN::A, &block) + query(name, resource_class) do |response| + # Resolv::DNS::Name doesn't retain the trailing dot. + name = name.sub(/\.$/, '') + + case response + when Message + yield response.answer.select{|record| record[0].to_s == name}.collect{|record| record[2].address} + else + yield [] + end + end + end + # Manages a single DNS question message across one or more servers. class Request include EventMachine::Deferrable def self.fetch(*args) \ No newline at end of file