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