Sha256: b7fe6e9bd0db9bf2d43cca4ab0f16dac6093fb61b6d0178686e4214af26808f3

Contents?: true

Size: 1.25 KB

Versions: 47

Compression:

Stored size: 1.25 KB

Contents

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

    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

47 entries across 47 versions & 2 rubygems

Version Path
specinfra-rb19-2.44.7 lib/specinfra/host_inventory.rb
specinfra-2.57.5 lib/specinfra/host_inventory.rb
specinfra-2.57.4 lib/specinfra/host_inventory.rb
specinfra-2.57.3 lib/specinfra/host_inventory.rb
specinfra-2.57.2 lib/specinfra/host_inventory.rb
specinfra-2.57.1 lib/specinfra/host_inventory.rb
specinfra-2.57.0 lib/specinfra/host_inventory.rb
specinfra-2.56.1 lib/specinfra/host_inventory.rb
specinfra-2.56.0 lib/specinfra/host_inventory.rb
specinfra-2.55.0 lib/specinfra/host_inventory.rb
specinfra-2.54.2 lib/specinfra/host_inventory.rb
specinfra-2.54.1 lib/specinfra/host_inventory.rb
specinfra-2.54.0 lib/specinfra/host_inventory.rb
specinfra-2.53.1 lib/specinfra/host_inventory.rb
specinfra-2.53.0 lib/specinfra/host_inventory.rb
specinfra-2.52.0 lib/specinfra/host_inventory.rb
specinfra-2.51.2 lib/specinfra/host_inventory.rb
specinfra-2.51.1 lib/specinfra/host_inventory.rb
specinfra-2.51.0 lib/specinfra/host_inventory.rb
specinfra-2.50.4 lib/specinfra/host_inventory.rb