File: hash.rb

package info (click to toggle)
ruby-ftw 0.0.49-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 548 kB
  • sloc: ruby: 1,922; makefile: 5
file content (25 lines) | stat: -rw-r--r-- 571 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require "ftw/namespace"

# Provide resolution name -> address mappings through hash lookups
class FTW::DNS::Hash
  private

  # A new hash dns resolver.
  #
  # @param [#[]] data Must be a hash-like thing responding to #[]
  def initialize(data={})
    @data = data
  end # def initialize

  # Resolve a hostname.
  #
  # It will return an array of all known addresses for the host.
  def resolve(hostname)
    result = @data[hostname]
    return nil if result.nil?
    return result if result.is_a?(Array)
    return [result]
  end # def resolve

  public(:resolve)
end