class Inspec::Resources::Package

def evaluate_missing_requirements

def evaluate_missing_requirements
  missing_requirements_string = @pkgman.missing_requirements.uniq.join(', ')
  return if missing_requirements_string.empty?
  raise Inspec::Exceptions::ResourceSkipped, "The following requirements are not met for this resource: #{missing_requirements_string}"
end

def held?(_provider = nil, _version = nil)

returns true it the package is held (if the OS supports it)
def held?(_provider = nil, _version = nil)
  info[:held] == true
end

def info

returns the package description
def info
  return @cache if !@cache.nil?
  # All `@pkgman.info` methods return `{}`. This matches that
  # behavior if `@pkgman` can't be determined, thus avoiding the
  # `undefined method 'info' for nil:NilClass` error
  return {} if @pkgman.nil?
  @pkgman.info(@package_name)
end

def initialize(package_name, opts = {}) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def initialize(package_name, opts = {}) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
  @package_name = package_name
  @name = @package_name
  @cache = nil
  # select package manager
  @pkgman = nil
  os = inspec.os
  if os.debian?
    @pkgman = Deb.new(inspec)
  elsif os.redhat? || %w{suse amazon fedora}.include?(os[:family])
    @pkgman = Rpm.new(inspec, opts)
  elsif ['arch'].include?(os[:name])
    @pkgman = Pacman.new(inspec)
  elsif ['darwin'].include?(os[:family])
    @pkgman = Brew.new(inspec)
  elsif os.windows?
    @pkgman = WindowsPkg.new(inspec)
  elsif ['aix'].include?(os[:family])
    @pkgman = BffPkg.new(inspec)
  elsif os.solaris?
    @pkgman = SolarisPkg.new(inspec)
  elsif ['hpux'].include?(os[:family])
    @pkgman = HpuxPkg.new(inspec)
  elsif ['alpine'].include?(os[:name])
    @pkgman = AlpinePkg.new(inspec)
  else
    raise Inspec::Exceptions::ResourceSkipped, 'The `package` resource is not supported on your OS yet.'
  end
  evaluate_missing_requirements
end

def installed?(_provider = nil, _version = nil)

returns true if the package is installed
def installed?(_provider = nil, _version = nil)
  info[:installed] == true
end

def to_s

def to_s
  "System Package #{@package_name}"
end

def version

return the package version
def version
  info = @pkgman.info(@package_name)
  info[:version]
end