Sha256: 39b2c98efda7175f4c2081521b679065b46f119b2ad280a5ed716de2d62f8dd2

Contents?: true

Size: 1.29 KB

Versions: 27

Compression:

Stored size: 1.29 KB

Contents

module Specinfra
  class HostInventory
    KEYS = %w{
      memory
      ec2
      hostname
      domain
      fqdn
      platform
      platform_version
      filesystem
      cpu
      virtualization
      kernel
      block_device
      user
      group
      facter
      ohai
    }

    include Enumerable

    attr_reader :backend

    def self.instance
      property[:host_inventory] ||= {}
      self.new(Specinfra.backend, property[:host_inventory])
    end

    def initialize(backend, inventory = {})
      @backend = backend
      @inventory = inventory
    end

    def [](key)
      @inventory[key.to_sym] ||= {}
      if @inventory[key.to_sym].empty?
        begin
          inventory_class = Specinfra::HostInventory.const_get(key.to_s.to_camel_case)
          @inventory[key.to_sym] = inventory_class.new(self).get
        rescue
          @inventory[key.to_sym] = nil
        end
      end
      @inventory[key.to_sym]
    end

    def each
      KEYS.each do |k|
        yield k, self[k]
      end
    end

    def each_key
      KEYS.each do |k|
        yield k
      end
    end

    def each_value
      KEYS.each do |k|
        yield self[k]
      end
    end

  end
end

require "specinfra/host_inventory/base"
Specinfra::HostInventory::KEYS.each do |k|
  require "specinfra/host_inventory/#{k}"
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
specinfra-2.76.9 lib/specinfra/host_inventory.rb
specinfra-2.76.8 lib/specinfra/host_inventory.rb
specinfra-2.76.7 lib/specinfra/host_inventory.rb
specinfra-2.76.6 lib/specinfra/host_inventory.rb
specinfra-2.76.5 lib/specinfra/host_inventory.rb
specinfra-2.76.4 lib/specinfra/host_inventory.rb
specinfra-2.76.3 lib/specinfra/host_inventory.rb
specinfra-2.76.2 lib/specinfra/host_inventory.rb
specinfra-2.76.1 lib/specinfra/host_inventory.rb
specinfra-2.76.0 lib/specinfra/host_inventory.rb
specinfra-2.75.1 lib/specinfra/host_inventory.rb
specinfra-2.75.0 lib/specinfra/host_inventory.rb
specinfra-2.74.0 lib/specinfra/host_inventory.rb
specinfra-2.73.4 lib/specinfra/host_inventory.rb
specinfra-2.73.3 lib/specinfra/host_inventory.rb
specinfra-2.73.2 lib/specinfra/host_inventory.rb
specinfra-2.73.1 lib/specinfra/host_inventory.rb
specinfra-2.73.0 lib/specinfra/host_inventory.rb
specinfra-2.72.1 lib/specinfra/host_inventory.rb
specinfra-2.72.0 lib/specinfra/host_inventory.rb