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
Public Class Methods
# 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
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
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
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
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
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
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
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
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
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
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
@return [String] the machine hostname
# File lib/config_curator/unit.rb, line 124 def hostname Socket.gethostname end
@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