Sha256: 8807f2c074d424eb07a5521d03f9fd64675517320011b2ee6beab6ed08e9c5f6

Contents?: true

Size: 1.31 KB

Versions: 56

Compression:

Stored size: 1.31 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
      mount
    }

    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

56 entries across 56 versions & 1 rubygems

Version Path
specinfra-2.91.0 lib/specinfra/host_inventory.rb
specinfra-2.90.1 lib/specinfra/host_inventory.rb
specinfra-2.90.0 lib/specinfra/host_inventory.rb
specinfra-2.89.0 lib/specinfra/host_inventory.rb
specinfra-2.88.2 lib/specinfra/host_inventory.rb
specinfra-2.88.1 lib/specinfra/host_inventory.rb
specinfra-2.88.0 lib/specinfra/host_inventory.rb
specinfra-2.87.2 lib/specinfra/host_inventory.rb
specinfra-2.87.1 lib/specinfra/host_inventory.rb
specinfra-2.87.0 lib/specinfra/host_inventory.rb
specinfra-2.86.0 lib/specinfra/host_inventory.rb
specinfra-2.85.1 lib/specinfra/host_inventory.rb
specinfra-2.85.0 lib/specinfra/host_inventory.rb
specinfra-2.84.1 lib/specinfra/host_inventory.rb
specinfra-2.84.0 lib/specinfra/host_inventory.rb
specinfra-2.83.4 lib/specinfra/host_inventory.rb
specinfra-2.83.3 lib/specinfra/host_inventory.rb
specinfra-2.83.2 lib/specinfra/host_inventory.rb
specinfra-2.83.1 lib/specinfra/host_inventory.rb
specinfra-2.83.0 lib/specinfra/host_inventory.rb