Class: Inspec::Resources::PipPackage

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

Instance Method Summary collapse

Constructor Details

#initialize(package_name) ⇒ PipPackage

Returns a new instance of PipPackage.



20
21
22
# File 'lib/resources/pip.rb', line 20

def initialize(package_name)
  @package_name = package_name
end

Instance Method Details

#infoObject



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

def info
  return @info if defined?(@info)

  @info = {}
  @info[:type] = 'pip'
  cmd = inspec.command("#{pip_cmd} show #{@package_name}")
  return @info if cmd.exit_status != 0

  params = SimpleConfig.new(
    cmd.stdout,
    assignment_re: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
    multiple_values: false,
  ).params
  @info[:name] = params['Name']
  @info[:version] = params['Version']
  @info[:installed] = true
  @info
end

#installed?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/resources/pip.rb', line 43

def installed?
  info[:installed] == true
end

#to_sObject



51
52
53
# File 'lib/resources/pip.rb', line 51

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

#versionObject



47
48
49
# File 'lib/resources/pip.rb', line 47

def version
  info[:version]
end