Class: Hocho::Config
- Inherits:
-
Object
- Object
- Hocho::Config
- Defined in:
- lib/hocho/config.rb
Constant Summary collapse
- DEFAULT_INVENTORY_PROVIDERS_CONFIG =
[file: {path: './hosts.yml'}]
Instance Attribute Summary collapse
-
#base_dir ⇒ Object
readonly
Returns the value of attribute base_dir.
Class Method Summary collapse
Instance Method Summary collapse
- #[](k) ⇒ Object
-
#initialize(hash, base_dir: '.') ⇒ Config
constructor
A new instance of Config.
- #inventory_providers ⇒ Object
- #property_providers ⇒ Object
Constructor Details
Instance Attribute Details
#base_dir ⇒ Object (readonly)
Returns the value of attribute base_dir.
20 21 22 |
# File 'lib/hocho/config.rb', line 20 def base_dir @base_dir end |
Class Method Details
.load(path) ⇒ Object
11 12 13 |
# File 'lib/hocho/config.rb', line 11 def self.load(path) new YAML.load_file(path.to_s), base_dir: File.dirname(path.to_s) end |
Instance Method Details
#[](k) ⇒ Object
22 23 24 |
# File 'lib/hocho/config.rb', line 22 def [](k) @config[k] end |
#inventory_providers ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hocho/config.rb', line 26 def inventory_providers @inventory_providers ||= begin provider_specs = (@config[:inventory_providers] || DEFAULT_INVENTORY_PROVIDERS_CONFIG) if provider_specs.kind_of?(Hash) provider_specs = [provider_specs] end provider_specs.flat_map do |spec| raise TypeError, 'config inventory_providers[] should be an Hash' unless spec.kind_of?(Hash) spec.map do |name, | InventoryProviders.find(name).new(**) end end end end |
#property_providers ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/hocho/config.rb', line 42 def property_providers @property_providers ||= begin provider_specs = (@config[:property_providers] || []) raise TypeError, 'config property_providers should be an Array' unless provider_specs.kind_of?(Array) provider_specs.flat_map do |spec| raise TypeError, 'config property_providers[] should be an Hash' unless spec.kind_of?(Hash) spec.map do |name, | PropertyProviders.find(name).new(**) end end end end |