Class: Inspec::Resources::Packages

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/resources/packages.rb

Instance Method Summary collapse

Constructor Details

#initialize(pattern) ⇒ Packages

Returns a new instance of Packages.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/inspec/resources/packages.rb', line 23

def initialize(pattern)
  os = inspec.os
  if os.debian?
    @pkgs = Debs.new(inspec)
  elsif os.redhat? || %w{suse amazon fedora}.include?(os[:family])
    @pkgs = Rpms.new(inspec)
  elsif ["alpine"].include?(os[:name])
    @pkgs = AlpinePkgs.new(inspec)
  else
    return skip_resource "The packages resource is not yet supported on OS #{inspec.os.name}"
  end

  @pattern = pattern_regexp(pattern)
  all_pkgs = @pkgs.build_package_list
  @list = all_pkgs.find_all do |hm|
    hm[:name] =~ @pattern
  end
end

Instance Method Details

#to_sObject



42
43
44
# File 'lib/inspec/resources/packages.rb', line 42

def to_s
  "Packages #{@pattern.class == String ? @pattern : @pattern.inspect}"
end