Class: FTW::DNS
- Inherits:
-
Object
- Object
- FTW::DNS
- Extended by:
- Singleton
- Defined in:
- lib/ftw/namespace.rb,
lib/ftw/dns.rb
Overview
I wrap whatever Ruby provides because it is historically very inconsistent in implementation behavior across ruby platforms and versions. In the future, this will probably implement the DNS protocol, but for now chill in the awkward, but already-written, ruby stdlib.
I didn’t really want to write a DNS library, but a consistent API and behavior is necessary for my continued sanity :)
Defined Under Namespace
Constant Summary collapse
- V4_IN_V6_PREFIX =
The ipv4-in-ipv6 address space prefix.
"0:" * 12
Instance Attribute Summary collapse
-
#resolvers ⇒ Object
readonly
An array of resolvers.
Instance Method Summary collapse
-
#resolve(hostname) ⇒ Object
Resolve a hostname.
-
#resolve_random(hostname) ⇒ Object
Resolve hostname and choose one of the results at random.
Methods included from Singleton
Instance Attribute Details
#resolvers ⇒ Object (readonly)
An array of resolvers. By default this includes a FTW::DNS::DNS instance.
20 21 22 |
# File 'lib/ftw/dns.rb', line 20 def resolvers @resolvers end |
Instance Method Details
#resolve(hostname) ⇒ Object
Resolve a hostname.
Returns an array of all addresses for this host. Empty array resolution failure.
36 37 38 39 40 41 |
# File 'lib/ftw/dns.rb', line 36 def resolve(hostname) return @resolvers.reduce([]) do |memo, resolver| result = resolver.resolve(hostname) memo += result unless result.nil? end end |
#resolve_random(hostname) ⇒ Object
Resolve hostname and choose one of the results at random.
Use this method if you are connecting to a hostname that resolves to multiple addresses.
47 48 49 50 |
# File 'lib/ftw/dns.rb', line 47 def resolve_random(hostname) addresses = resolve(hostname) return addresses[rand(addresses.size)] end |