class Loom::Inventory::InventoryFileSet

Public Class Methods

new(inventory_files) click to toggle source
# File lib/loom/inventory.rb, line 84
def initialize(inventory_files)
  @hostgroup_map = nil
  @hostlist = nil

  @raw_inventories = inventory_files.map do |path|
    Loom.log.debug "loading inventory file #{path}"
    YAML.load_file path
  end
end

Public Instance Methods

hostgroup_map() click to toggle source
# File lib/loom/inventory.rb, line 94
def hostgroup_map
  @hostgroup_map ||= @raw_inventories.reduce({}) do |map, i|
    i.each do |entry|
      if entry.is_a? Hash
        Loom.log.debug "merging groups in #{entry}"
        entry.each do |k,v|
          map[k.to_sym] = v
        end
      end
    end
    map
  end
end
hostlist() click to toggle source
# File lib/loom/inventory.rb, line 108
def hostlist
  @hostlist ||= @raw_inventories.map do |i|
    i.map do |entry|
      case entry
      when String
        entry
      when Hash
        entry.values
      else
        raise InventoryFileEntryError, "unexpected entry #{entry}"
      end
    end
  end.flatten
end