Sha256: c61c1a74f23116de9379d716cf1144132c68c8b32e0375a8c805e92fac2d86ff

Contents?: true

Size: 1.06 KB

Versions: 19

Compression:

Stored size: 1.06 KB

Contents

module Specinfra
  class HostInventory
    include Singleton
    include Enumerable

    def initialize
      property[:host_inventory] ||= {}
      @inventory = property[:host_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.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

    def keys
      %w{
        memory
        ec2
        hostname
        domain
        fqdn
        platform
        platform_version
        filesystem
        cpu
      }
    end
  end
end

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

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
specinfra-2.23.0 lib/specinfra/host_inventory.rb
specinfra-2.22.0 lib/specinfra/host_inventory.rb
specinfra-2.21.1 lib/specinfra/host_inventory.rb
specinfra-2.21.0 lib/specinfra/host_inventory.rb
specinfra-2.20.2 lib/specinfra/host_inventory.rb
specinfra-2.20.1 lib/specinfra/host_inventory.rb
specinfra-2.20.0 lib/specinfra/host_inventory.rb
specinfra-2.19.6 lib/specinfra/host_inventory.rb
specinfra-2.19.5 lib/specinfra/host_inventory.rb
specinfra-2.19.4 lib/specinfra/host_inventory.rb
specinfra-2.19.3 lib/specinfra/host_inventory.rb
specinfra-2.19.2 lib/specinfra/host_inventory.rb
specinfra-2.19.1 lib/specinfra/host_inventory.rb
specinfra-2.19.0 lib/specinfra/host_inventory.rb
specinfra-2.18.3 lib/specinfra/host_inventory.rb
specinfra-2.18.2 lib/specinfra/host_inventory.rb
specinfra-2.18.1 lib/specinfra/host_inventory.rb
specinfra-2.18.0 lib/specinfra/host_inventory.rb
specinfra-2.17.1 lib/specinfra/host_inventory.rb