Class: DNSResolver::Resolver

Inherits:
Object
  • Object
show all
Includes:
Celluloid::IO, Config, Exceptions, Logger
Defined in:
lib/dnsresolver/resolver.rb

Constant Summary

Constants included from Config

Config::DEFAULTS, Config::DNSRUBY_DEFAULTS

Instance Method Summary collapse

Methods included from Config

#dnsruby_settings, #load!, #load_configuration, #settings

Methods included from Logger

#logger, #logger=

Constructor Details

#initialize(nameservers, dnsruby_options = {}) ⇒ Resolver

Returns a new instance of Resolver.



8
9
10
11
12
# File 'lib/dnsresolver/resolver.rb', line 8

def initialize(nameservers, dnsruby_options = {})
  options = { :config_info => { :nameserver => nameservers[0] }}.merge(Config.dnsruby_settings.merge(dnsruby_options))
  @resolver = Dnsruby::Resolver.new(options)
  self.add_nameservers nameservers
end

Instance Method Details

#add_nameservers(nameservers) ⇒ Object



18
19
20
# File 'lib/dnsresolver/resolver.rb', line 18

def add_nameservers(nameservers)
  nameservers.each { |nameserver| @resolver.config.add_nameserver nameserver }
end

#naptr_query(name, options = {}) ⇒ Object



47
48
49
# File 'lib/dnsresolver/resolver.rb', line 47

def naptr_query(name, options = {})
  self.query(name, options.merge(:record_type => Dnsruby::Types.NAPTR))
end

#perform_query_callback(callback, answers, exception = nil) ⇒ Object



22
23
24
# File 'lib/dnsresolver/resolver.rb', line 22

def perform_query_callback(callback, answers, exception = nil)
  callback.call answers, exception
end

#query(name, options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dnsresolver/resolver.rb', line 26

def query(name, options = {})
  answers = []
  exception = nil
  record_type = options[:record_type] || Dnsruby::Types.A
  dns_class = options[:dns_class] || Dnsruby::Classes.IN
  callback = options[:callback]

  begin
    q = self.resolver.query(name, record_type, dns_class)
    q.each_answer { |answer| answers << answer }
  rescue Dnsruby::NXDomain => exception
    logger.debug "DNSResolver query, could not resolve '#{name}'"
  rescue Exception => exception
    logger.error "DNSResolver query, '#{name}' #{exception.message}"
  end

  perform_query_callback! callback, answers, exception if callback

  answers
end

#resolverObject



14
15
16
# File 'lib/dnsresolver/resolver.rb', line 14

def resolver
  @resolver
end