Class: ConfigCurator::Collection
- Inherits:
-
Object
- Object
- ConfigCurator::Collection
- Defined in:
- lib/config_curator/collection.rb
Overview
Manages collections of units.
Constant Summary collapse
- UNIT_TYPES =
Supported unit types.
%i(unit component config_file symlink)
- UNIT_ATTRIBUTES =
The possible attributes specific to each unit type. This should not include generic attributes such as Unit#source and Unit#destination.
{ unit: %i(hosts packages), component: %i(hosts packages fmode dmode owner group backend), config_file: %i(hosts packages fmode owner group), symlink: %i(hosts packages) }
Instance Attribute Summary collapse
-
#logger ⇒ Logger
Logger instance to use.
-
#manifest ⇒ Object
Returns the value of attribute manifest.
-
#units ⇒ Hash
Unit objects defined by the manifest and organized by type.
Instance Method Summary collapse
-
#create_unit(type, attributes: {}) ⇒ Unit
Creates a new unit object for the collection.
-
#initialize(manifest_path: nil, logger: nil) ⇒ Collection
constructor
A new instance of Collection.
-
#install ⇒ Boolean?
Installs all units from the manifest.
-
#install?(quiet: false) ⇒ Boolean
Checks all units in the manifest for any detectable install issues.
-
#load_manifest(file) ⇒ Hash
Loads the manifest from file.
Constructor Details
#initialize(manifest_path: nil, logger: nil) ⇒ Collection
Returns a new instance of Collection.
26 27 28 29 |
# File 'lib/config_curator/collection.rb', line 26 def initialize(manifest_path: nil, logger: nil) self.logger = logger unless logger.nil? load_manifest manifest_path unless manifest_path.nil? end |
Instance Attribute Details
#logger ⇒ Logger
Logger instance to use.
33 34 35 |
# File 'lib/config_curator/collection.rb', line 33 def logger @logger end |
#manifest ⇒ Object
Returns the value of attribute manifest.
24 25 26 |
# File 'lib/config_curator/collection.rb', line 24 def manifest @manifest end |
#units ⇒ Hash
Unit objects defined by the manifest and organized by type.
49 50 51 |
# File 'lib/config_curator/collection.rb', line 49 def units @units end |
Instance Method Details
#create_unit(type, attributes: {}) ⇒ Unit
Creates a new unit object for the collection.
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/config_curator/collection.rb', line 93 def create_unit(type, attributes: {}) "#{self.class.name.split('::').first}::#{type.to_s.camelize}".constantize .new(options: , logger: logger).tap do |unit| {src: :source, dst: :destination}.each do |k, v| unit.send "#{v}=".to_sym, attributes[k] unless attributes[k].nil? end UNIT_ATTRIBUTES[type].each do |v| unit.send "#{v}=".to_sym, defaults[v] unless defaults[v].nil? unit.send "#{v}=".to_sym, attributes[v] unless attributes[v].nil? end end end |
#install ⇒ Boolean?
Installs all units from the manifest.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/config_curator/collection.rb', line 65 def install return false unless install? quiet: !(logger.level == Logger::DEBUG) UNIT_TYPES.each do |type| units[type.to_s.pluralize.to_sym].each do |unit| return nil unless install_unit(unit, type) end end true end |
#install?(quiet: false) ⇒ Boolean
Checks all units in the manifest for any detectable install issues.
79 80 81 82 83 84 85 86 87 |
# File 'lib/config_curator/collection.rb', line 79 def install?(quiet: false) result = true UNIT_TYPES.each do |type| units[type.to_s.pluralize.to_sym].each do |unit| result = install_unit?(unit, type, quiet) ? result : false end end result end |
#load_manifest(file) ⇒ Hash
Loads the manifest from file.
42 43 44 45 |
# File 'lib/config_curator/collection.rb', line 42 def load_manifest(file) self.manifest = ActiveSupport::HashWithIndifferentAccess.new YAML.load_file(file) end |