Class: Inspec::Resources::PipPackage

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

Instance Method Summary collapse

Constructor Details

#initialize(package_name, pip_path = nil) ⇒ PipPackage

Returns a new instance of PipPackage.



26
27
28
29
30
31
# File 'lib/inspec/resources/pip.rb', line 26

def initialize(package_name, pip_path = nil)
  @package_name = package_name
  @pip_cmd = pip_path || default_pip_path

  return skip_resource "pip not found" if @pip_cmd.nil?
end

Instance Method Details

#infoObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/inspec/resources/pip.rb', line 33

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

  @info = {}
  @info[:type] = "pip"
  return @info unless cmd_successful?

  params = SimpleConfig.new(
    cmd.stdout,
    assignment_regex: /^\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)


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

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

#resource_idObject



59
60
61
# File 'lib/inspec/resources/pip.rb', line 59

def resource_id
  @package_name || "pip"
end

#to_sObject



63
64
65
# File 'lib/inspec/resources/pip.rb', line 63

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

#versionObject



55
56
57
# File 'lib/inspec/resources/pip.rb', line 55

def version
  info[:version]
end