Created
June 29, 2010 21:51
-
-
Save cgriego/457871 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Chef | |
class Recipe | |
def has_gem?(name, version=nil) | |
if !$GEM_LIST | |
gems = {} | |
`gem list --local`.each_line do |line| | |
gems[$1.to_sym] = $2.split(/, /) if line =~ /^(.*) \(([^\)]*)\)$/ | |
end | |
$GEM_LIST = gems | |
end | |
if $GEM_LIST[name.to_sym] | |
if version | |
if $GEM_LIST[name.to_sym].include?(version) | |
Chef::Log.info("Gem: #{name}:#{version} already installed, skipping") | |
return true | |
end | |
else | |
Chef::Log.info("Gem: #{name} already installed, skipping") | |
return true | |
end | |
end | |
false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment