class Srvy::Resolver
Attributes
cache[R]
Public Class Methods
new(options={})
click to toggle source
# File lib/srvy/resolver.rb, line 8 def initialize(options={}) @dns = Net::DNS::Resolver.new if options[:nameserver] @dns.nameservers = options[:nameserver] end cache_size = options[:cache_size] || 100 @cache = LruRedux::Cache.new(cache_size) #cache of host -> result kv pairs end
Public Instance Methods
get(host)
click to toggle source
Gets the Srvy::Result
from the cache or from dns.
host - The String hostname to query for SRV records.
Returns the Srvy::Result
for that hostname
# File lib/srvy/resolver.rb, line 49 def get(host) result = @cache[host] if !result || result.expired? result = Srvy::Result.from_dns get_dns(host) @cache[host] = result end result end
get_all(host, format=:host_port)
click to toggle source
# File lib/srvy/resolver.rb, line 34 def get_all(host, format=:host_port) result = get(host).get_all Srvy::Formatters.format_many(format, result) end
get_dns(host)
click to toggle source
# File lib/srvy/resolver.rb, line 39 def get_dns(host) @dns.search(host, Net::DNS::SRV) end
get_many(host, format=:host_port)
click to toggle source
# File lib/srvy/resolver.rb, line 29 def get_many(host, format=:host_port) result = get(host).get_many Srvy::Formatters.format_many(format, result) end
get_single(host, format=:host_port)
click to toggle source
# File lib/srvy/resolver.rb, line 23 def get_single(host, format=:host_port) result = get(host).get_single Srvy::Formatters.format_single(format, result) end
inspect()
click to toggle source
# File lib/srvy/resolver.rb, line 19 def inspect "#<Srvy::Resolver:#{object_id} dns=#{@dns.nameservers.inspect}>" end