class Google::Cloud::Env::ComputeSMBIOS


You can provide an override to “mock out” the behavior of this object.
Registry on Windows.
This information lives at a file system path on Linux, but in the
process is running on a Google compute platform.
Access to the SMBIOS information needed to determine if this Ruby
#

def google_compute?

Returns:
  • (true, false) -
def google_compute?
  product_name.include? "Google"
end

def initialize


Create an SMBIOS access object
#
def initialize
  @product_name_cache = LazyValue.new { load_product_name }
  @override_product_name = nil
end

def load_product_name

def load_product_name
  begin
    require "win32/registry"
    Win32::Registry::HKEY_LOCAL_MACHINE.open WINDOWS_KEYPATH do |reg|
      return [reg[WINDOWS_KEYNAME].to_s, :windows]
    end
  rescue LoadError
    # Fall through to the Linux routine
  rescue StandardError => e
    # With JRuby 10, a Fiddle::DLError is raised, In the case the fiddle gem is not
    # loadable, safely assert the error type without relying on the Fiddle namespace
    # having been loaded.
    raise e unless e.class.name == "Fiddle::DLError" # rubocop:disable Style/ClassEqualityComparison
    # Fall through to the Linux routine
  end
  begin
    File.open LINUX_FILEPATH do |file|
      return [file.readline(chomp: true), :linux]
    end
  rescue IOError, SystemCallError
    ["", :error]
  end
end

def product_name

Returns:
  • (String) - Product name, or the empty string if not found.
def product_name
  @override_product_name || @product_name_cache.get.first
end

def product_name_source

Returns:
  • (Symbol) - The source
def product_name_source
  @override_product_name ? :override : @product_name_cache.get.last
end

def with_override_product_name override_name

Parameters:
  • override_name (nil, String) --
def with_override_product_name override_name
  old_override = @override_product_name
  begin
    @override_product_name = override_name
    yield
  ensure
    @override_product_name = old_override
  end
end