mirror of
https://github.com/inspec/inspec
synced 2024-11-27 15:10:44 +00:00
4965bfd36d
Dont return nil als a falsy result. Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
44 lines
880 B
Ruby
44 lines
880 B
Ruby
# encoding: utf-8
|
|
|
|
# Usage:
|
|
# describe gem('rubocop') do
|
|
# it { should be_installed }
|
|
# end
|
|
class GemPackage < Vulcano.resource(1)
|
|
name 'gem'
|
|
|
|
def initialize(package_name)
|
|
@package_name = package_name
|
|
end
|
|
|
|
def info
|
|
return @info unless @info.nil?
|
|
|
|
cmd = vulcano.run_command("gem list --local -a -q \^#{@package_name}\$")
|
|
@info = {
|
|
installed: cmd.exit_status == 0,
|
|
type: 'gem',
|
|
}
|
|
return @info unless @info[:installed]
|
|
|
|
# extract package name and version
|
|
# parses data like winrm (1.3.4, 1.3.3)
|
|
params = /^\s*([^\(]*?)\s*\((.*?)\)\s*$/.match(cmd.stdout.chomp)
|
|
versions = params[2].split(',')
|
|
@info[:name] = params[1]
|
|
@info[:version] = versions[0]
|
|
@info
|
|
end
|
|
|
|
def installed?
|
|
info[:installed] == true
|
|
end
|
|
|
|
def version
|
|
info[:version]
|
|
end
|
|
|
|
def to_s
|
|
"pip package #{@package_name}"
|
|
end
|
|
end
|