class Hocho::Config

Constants

DEFAULT_INVENTORY_PROVIDERS_CONFIG

Attributes

base_dir[R]

Public Class Methods

load(path) click to toggle source
# 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
new(hash, base_dir: '.') click to toggle source
# File lib/hocho/config.rb, line 15
def initialize(hash, base_dir: '.')
  @config = Hocho::Utils::Symbolize.keys_of(hash)
  @base_dir = Pathname(base_dir)
end

Public Instance Methods

[](k) click to toggle source
# File lib/hocho/config.rb, line 22
def [](k)
  @config[k]
end
inventory_providers() click to toggle source
# 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, options|
        InventoryProviders.find(name).new(**options)
      end
    end
  end
end
property_providers() click to toggle source
# 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, options|
        PropertyProviders.find(name).new(**options)
      end
    end
  end
end