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, # 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 ⇒ Object
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.
Constructor Details
#initialize(options: {}, logger: nil) ⇒ Unit
25 26 27 28 |
# File 'lib/config_curator/unit.rb', line 25 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.
61 62 63 |
# File 'lib/config_curator/unit.rb', line 61 def hosts @hosts end |
#logger ⇒ Logger
Logger instance to use.
40 41 42 |
# File 'lib/config_curator/unit.rb', line 40 def logger @logger end |
#packages ⇒ Array
Unit installed only if listed packages are installed.
67 68 69 |
# File 'lib/config_curator/unit.rb', line 67 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.
92 93 94 95 |
# File 'lib/config_curator/unit.rb', line 92 def allowed_host? return true if hosts.empty? hosts.include? hostname end |
#destination_path ⇒ String
Full path to destination.
54 55 56 |
# File 'lib/config_curator/unit.rb', line 54 def destination_path File. File.join([:root], destination) unless destination.nil? end |
#install ⇒ Object
Installs the unit.
77 78 79 80 |
# File 'lib/config_curator/unit.rb', line 77 def install return false unless install? true end |
#install? ⇒ Boolean
Checks if the unit should be installed.
84 85 86 87 88 |
# File 'lib/config_curator/unit.rb', line 84 def install? return false unless allowed_host? return false unless packages_installed? true end |
#options(options = {}) ⇒ Hash
Uses DEFAULT_OPTIONS as initial value.
33 34 35 36 |
# File 'lib/config_curator/unit.rb', line 33 def ( = {}) ||= DEFAULT_OPTIONS = .merge end |
#package_lookup ⇒ Object
A PackageLookup object for this unit.
72 73 74 |
# File 'lib/config_curator/unit.rb', line 72 def package_lookup @package_lookup ||= PackageLookup.new tool: [:package_tool] end |
#packages_installed? ⇒ Boolean
Checks if the packages required for this unit are installed.
99 100 101 |
# File 'lib/config_curator/unit.rb', line 99 def packages_installed? packages.map(&method(:pkg_exists?)).delete_if { |e| e }.empty? end |
#source_path ⇒ String
Full path to source.
48 49 50 |
# File 'lib/config_curator/unit.rb', line 48 def source_path File. source unless source.nil? end |