Class: ConfigCurator::Unit
- Inherits:
-
Object
- Object
- ConfigCurator::Unit
- Includes:
- Utils
- Defined in:
- lib/config_curator/unit.rb
Overview
A unit is the base class for a type of configuration that should be installed. All units must specify a #source and a #destination.
Direct Known Subclasses
Defined Under Namespace
Classes: InstallFailed
Constant Summary collapse
- DEFAULT_OPTIONS =
Default #options.
{ # Unit installed relative to this path. root: Dir.home, # Automatically uninstall units that would not be installed. uninstall: false, # Package tool to use. See #package_lookup. package_tool: nil }
Instance Attribute Summary collapse
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#hosts ⇒ Array
Unit will be installed on these hosts.
-
#logger ⇒ Logger
Logger instance to use.
-
#packages ⇒ Array
Unit installed only if listed packages are installed.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
-
#allowed_host? ⇒ Boolean
Checks if the unit should be installed on this host.
-
#destination_path ⇒ String
Full path to destination.
-
#initialize(options: {}, logger: nil) ⇒ Unit
constructor
A new instance of Unit.
-
#install ⇒ Boolean
Installs the unit.
-
#install? ⇒ Boolean
Checks if the unit should be installed.
-
#options(options = {}) ⇒ Hash
Uses DEFAULT_OPTIONS as initial value.
-
#package_lookup ⇒ Object
A PackageLookup object for this unit.
-
#packages_installed? ⇒ Boolean
Checks if the packages required for this unit are installed.
-
#source_path ⇒ String
Full path to source.
-
#uninstall(force: false) ⇒ Boolean
Uninstalls the unit.
-
#uninstall? ⇒ Boolean
Checks if the unit should be uninstalled.
Constructor Details
#initialize(options: {}, logger: nil) ⇒ Unit
Returns a new instance of Unit.
28 29 30 31 |
# File 'lib/config_curator/unit.rb', line 28 def initialize(options: {}, logger: nil) self. self.logger = logger unless logger.nil? end |
Instance Attribute Details
#destination ⇒ Object
Returns the value of attribute destination.
14 15 16 |
# File 'lib/config_curator/unit.rb', line 14 def destination @destination end |
#hosts ⇒ Array
Unit will be installed on these hosts. If empty, installed on any host.
64 65 66 |
# File 'lib/config_curator/unit.rb', line 64 def hosts @hosts end |
#logger ⇒ Logger
Logger instance to use.
43 44 45 |
# File 'lib/config_curator/unit.rb', line 43 def logger @logger end |
#packages ⇒ Array
Unit installed only if listed packages are installed.
70 71 72 |
# File 'lib/config_curator/unit.rb', line 70 def packages @packages end |
#source ⇒ Object
Returns the value of attribute source.
14 15 16 |
# File 'lib/config_curator/unit.rb', line 14 def source @source end |
Instance Method Details
#allowed_host? ⇒ Boolean
Checks if the unit should be installed on this host.
110 111 112 113 |
# File 'lib/config_curator/unit.rb', line 110 def allowed_host? return true if hosts.empty? hosts.include? hostname end |
#destination_path ⇒ String
Full path to destination.
57 58 59 |
# File 'lib/config_curator/unit.rb', line 57 def destination_path File. File.join([:root], destination) unless destination.nil? end |
#install ⇒ Boolean
Installs the unit.
95 96 97 98 |
# File 'lib/config_curator/unit.rb', line 95 def install return false unless install? true end |
#install? ⇒ Boolean
Checks if the unit should be installed.
102 103 104 105 106 |
# File 'lib/config_curator/unit.rb', line 102 def install? return false unless allowed_host? return false unless packages_installed? true end |
#options(options = {}) ⇒ Hash
Uses DEFAULT_OPTIONS as initial value.
36 37 38 39 |
# File 'lib/config_curator/unit.rb', line 36 def ( = {}) @options ||= DEFAULT_OPTIONS @options = @options.merge end |
#package_lookup ⇒ Object
A PackageLookup object for this unit.
75 76 77 |
# File 'lib/config_curator/unit.rb', line 75 def package_lookup @package_lookup ||= PackageLookup.new tool: [:package_tool] end |
#packages_installed? ⇒ Boolean
Checks if the packages required for this unit are installed.
117 118 119 |
# File 'lib/config_curator/unit.rb', line 117 def packages_installed? packages.map(&method(:pkg_exists?)).delete_if { |e| e }.empty? end |
#source_path ⇒ String
Full path to source.
51 52 53 |
# File 'lib/config_curator/unit.rb', line 51 def source_path File. source unless source.nil? end |
#uninstall(force: false) ⇒ Boolean
Uninstalls the unit.
81 82 83 84 |
# File 'lib/config_curator/unit.rb', line 81 def uninstall(force: false) return true if uninstall? || force false end |
#uninstall? ⇒ Boolean
Checks if the unit should be uninstalled.
88 89 90 91 |
# File 'lib/config_curator/unit.rb', line 88 def uninstall? return true if !install? && [:uninstall] false end |