Sha256: e0efa339ed5c16bae5716779793cfce19ee98cbb7f91c8bc324a86ea2c9ab71f

Contents?: true

Size: 976 Bytes

Versions: 6

Compression:

Stored size: 976 Bytes

Contents

require 'net/dns'

module Auger

  class Project
    def dns(port = 53, &block)
      @connections << Dns.load(port, &block)
    end
  end
  
  class Dns < Auger::Connection
    def open(host, options)
      options[:nameserver] = host
      ## resolver checks args and raises error if no matching method, so only pass valid options
      safe_options = options.select{ |key| Net::DNS::Resolver.method_defined? key }
      dns = Net::DNS::Resolver.new(safe_options)
      dns.use_tcp = true if options[:use_tcp]
      dns
    end

    def close(dns)
      dns = nil
    end

    def domain(&block)
      @requests << DnsDomainRequest.load(nil, &block)
    end

    def query(name, &block)
      @requests << DnsQueryRequest.load(name, &block)
    end
  end

  class DnsDomainRequest < Auger::Request
    def run(dns, ignored_arg)
      dns.domain
    end
  end
  
  class DnsQueryRequest < Auger::Request
    def run(dns, ignored_arg)
      dns.query(@arg)
    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
auger-1.4.6 lib/auger/plugin/dns.rb
auger-1.4.5 lib/auger/plugin/dns.rb
auger-1.4.4 lib/auger/plugin/dns.rb
auger-1.4.3 lib/auger/plugin/dns.rb
auger-1.4.2 lib/auger/plugin/dns.rb
auger-1.4.1 lib/auger/plugin/dns.rb