Method: Inspec::Resources::Package#initialize

Defined in:
lib/resources/package.rb

#initialize(package_name, opts = {}) ⇒ Package

rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/resources/package.rb', line 22

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