2015-09-08 22:11:42 +00:00
|
|
|
# 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
|
2015-09-17 08:53:33 +00:00
|
|
|
return @info unless @info.nil?
|
|
|
|
|
2015-09-08 22:11:42 +00:00
|
|
|
cmd = vulcano.run_command("gem list --local -a -q \^#{@package_name}\$")
|
2015-09-17 08:53:33 +00:00
|
|
|
@info = {
|
|
|
|
installed: cmd.exit_status == 0,
|
|
|
|
type: 'gem',
|
|
|
|
}
|
|
|
|
return @info unless @info[:installed]
|
2015-09-08 22:11:42 +00:00
|
|
|
|
|
|
|
# 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(',')
|
2015-09-17 08:53:33 +00:00
|
|
|
@info[:name] = params[1]
|
|
|
|
@info[:version] = versions[0]
|
|
|
|
@info
|
2015-09-08 22:11:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def installed?
|
2015-09-17 18:51:06 +00:00
|
|
|
info[:installed] == true
|
2015-09-08 22:11:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def version
|
2015-09-17 08:53:33 +00:00
|
|
|
info[:version]
|
2015-09-08 22:11:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"pip package #{@package_name}"
|
|
|
|
end
|
|
|
|
end
|