class ConfigCurator::Unit

A unit is the base class for a type of configuration that should be installed. All units must specify a {#source} and a {#destination}.

Constants

DEFAULT_OPTIONS

Default {#options}.

Attributes

destination[RW]
hosts[RW]
logger[RW]
packages[RW]
source[RW]

Public Class Methods

new(options: {}, logger: nil) click to toggle source
# File lib/config_curator/unit.rb, line 28
def initialize(options: {}, logger: nil)
  self.options options
  self.logger = logger unless logger.nil?
end

Public Instance Methods

allowed_host?() click to toggle source

Checks if the unit should be installed on this host. @return [Boolean] if the hostname is in {#hosts}

# File lib/config_curator/unit.rb, line 110
def allowed_host?
  return true if hosts.empty?
  hosts.include? hostname
end
destination_path() click to toggle source

Full path to destination. @return [String] expanded path to destination

# File lib/config_curator/unit.rb, line 57
def destination_path
  File.expand_path File.join(options[:root], destination) unless destination.nil?
end
install() click to toggle source

Installs the unit. @return [Boolean] if the unit was installed

# File lib/config_curator/unit.rb, line 95
def install
  return false unless install?
  true
end
install?() click to toggle source

Checks if the unit should be installed. @return [Boolean] if the unit should be installed

# File lib/config_curator/unit.rb, line 102
def install?
  return false unless allowed_host?
  return false unless packages_installed?
  true
end
options(options = {}) click to toggle source

Uses {DEFAULT_OPTIONS} as initial value. @param options [Hash] merged with current options @return [Hash] current options

# File lib/config_curator/unit.rb, line 36
def options(options = {})
  @options ||= DEFAULT_OPTIONS
  @options = @options.merge options
end
package_lookup() click to toggle source

A {PackageLookup} object for this unit.

# File lib/config_curator/unit.rb, line 75
def package_lookup
  @package_lookup ||= PackageLookup.new tool: options[:package_tool]
end
packages_installed?() click to toggle source

Checks if the packages required for this unit are installed. @return [Boolean] if the packages in {#packages} are installed

# File lib/config_curator/unit.rb, line 117
def packages_installed?
  packages.map(&method(:pkg_exists?)).delete_if { |e| e }.empty?
end
source_path() click to toggle source

Full path to source. @return [String] expanded path to source

# File lib/config_curator/unit.rb, line 51
def source_path
  File.expand_path source unless source.nil?
end
uninstall(force: false) click to toggle source

Uninstalls the unit. @return [Boolean] if the unit was uninstalled

# File lib/config_curator/unit.rb, line 81
def uninstall(force: false)
  return true if uninstall? || force
  false
end
uninstall?() click to toggle source

Checks if the unit should be uninstalled. @return [Boolean] if the unit should be uninstalled

# File lib/config_curator/unit.rb, line 88
def uninstall?
  return true if !install? && options[:uninstall]
  false
end

Private Instance Methods

hostname() click to toggle source

@return [String] the machine hostname

# File lib/config_curator/unit.rb, line 124
def hostname
  Socket.gethostname
end
pkg_exists?(pkg) click to toggle source

@return [Boolean] if the package exists on the system

# File lib/config_curator/unit.rb, line 129
def pkg_exists?(pkg)
  package_lookup.installed? pkg
end