Class AutomateIt::AddressManager::Portable
In: lib/automateit/address_manager/portable.rb
Parent: AutomateIt::AddressManager::BaseDriver

AddressManager::Portable

A pure-Ruby, portable driver for the AddressManager which provides minimal support for querying the hostname using sockets. Although it lacks advanced features found in other drivers, it will work on all platforms.

Methods

addresses   has?   hostnames  

Public Instance methods

See AddressManager#addresses

[Source]

# File lib/automateit/address_manager/portable.rb, line 31
  def addresses
    results = Set.new("127.0.0.1")
    results.merge(TCPSocket.gethostbyname(Socket.gethostname)[3]) rescue SocketError
    return results.flatten
  end

See AddressManager#has?

[Source]

# File lib/automateit/address_manager/portable.rb, line 13
  def has?(opts)
    raise NotImplementedError.new("this driver doesn't support queries for devices or labels") if opts[:device] or opts[:label]
    result = true
    result &= addresses.include?(opts[:address]) if opts[:address]
    return result
  end

See AddressManager#hostnames

[Source]

# File lib/automateit/address_manager/portable.rb, line 21
  def hostnames
    results = []
    results << Socket.gethostname
    results << "localhost"
    results += Socket.gethostbyname(Socket.gethostname)[1] rescue SocketError
    results += results.map{|name| hostnames_for(name)}.flatten
    return results.sort.uniq
  end

[Validate]