Class: AutomateIt::AddressManager::Portable

Inherits:
BaseDriver show all
Defined in:
lib/automateit/address_manager/portable.rb

Overview

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.

Constant Summary

Constants inherited from Plugin::Driver

Plugin::Driver::BASE_DRIVER_NAME

Constants included from Constants

Constants::HELPERS_DIR, Constants::INSTALL_DIR, Constants::PERROR, Constants::PEXEC, Constants::PNOTE, Constants::WARNING_BOILERPLATE

Instance Attribute Summary

Attributes inherited from Plugin::Driver

#manager

Attributes inherited from Common

#interpreter

Instance Method Summary collapse

Methods inherited from BaseDriver

#hostnames_for

Methods inherited from Plugin::Driver

abstract_driver, #available?, base_driver, base_driver?, depends_on, inherited, manager_token, #setup

Methods inherited from Plugin::Base

#setup, #token, token

Methods inherited from Common

#initialize, #log, #nitpick, #noop, #noop=, #noop?, #preview, #preview=, #preview?, #preview_for, #setup, #superuser?, #writing, #writing=, #writing?

Constructor Details

This class inherits a constructor from AutomateIt::Common

Instance Method Details

#addressesObject

See AddressManager#addresses



32
33
34
35
36
# File 'lib/automateit/address_manager/portable.rb', line 32

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

#has?(opts) ⇒ Boolean

See AddressManager#has?

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


13
14
15
16
17
18
# 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

#hostnamesObject

See AddressManager#hostnames



21
22
23
24
25
26
27
28
29
# File 'lib/automateit/address_manager/portable.rb', line 21

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

#suitability(method, *args) ⇒ Object

:nodoc:



8
9
10
# File 'lib/automateit/address_manager/portable.rb', line 8

def suitability(method, *args) # :nodoc:
  return 1
end