Sha256: 37ea0dc4263756c2b4107ad1fe1ec0316fa56ebdde4c9e7281efdb68b8df2396

Contents?: true

Size: 1.17 KB

Versions: 31

Compression:

Stored size: 1.17 KB

Contents

# == 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.
class AutomateIt::AddressManager::Portable < AutomateIt::AddressManager::BaseDriver
  def suitability(method, *args) # :nodoc:
    return 1
  end

  # See AddressManager#has?
  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
  def hostnames
    results = Set.new
    results << Socket.gethostname
    results.merge(Socket.gethostbyname(Socket.gethostname)[1]) rescue SocketError

    results.each{|name| results.merge(hostnames_for(name))}
    results << "localhost"
    return results.to_a.sort
  end

  # See AddressManager#addresses
  def addresses
    results = Set.new("127.0.0.1")
    results.merge(TCPSocket.gethostbyname(Socket.gethostname)[3]) rescue SocketError
    return results.flatten
  end
end

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
automate-it-0.9.2 lib/automateit/address_manager/portable.rb
automate-it-0.9.1 lib/automateit/address_manager/portable.rb
automate-it-0.9.0 lib/automateit/address_manager/portable.rb
automateit-0.70923 lib/automateit/address_manager/portable.rb
automateit-0.70930 lib/automateit/address_manager/portable.rb
automateit-0.71003 lib/automateit/address_manager/portable.rb
automateit-0.70928 lib/automateit/address_manager/portable.rb
automateit-0.71031.1 lib/automateit/address_manager/portable.rb
automateit-0.71031.2 lib/automateit/address_manager/portable.rb
automateit-0.71006 lib/automateit/address_manager/portable.rb
automateit-0.71017 lib/automateit/address_manager/portable.rb
automateit-0.71021 lib/automateit/address_manager/portable.rb
automateit-0.71012 lib/automateit/address_manager/portable.rb
automateit-0.71030 lib/automateit/address_manager/portable.rb
automateit-0.71101 lib/automateit/address_manager/portable.rb
automateit-0.71102 lib/automateit/address_manager/portable.rb
automateit-0.71103 lib/automateit/address_manager/portable.rb
automateit-0.71031 lib/automateit/address_manager/portable.rb
automateit-0.71101.2 lib/automateit/address_manager/portable.rb
automateit-0.71101.1 lib/automateit/address_manager/portable.rb