Created
March 30, 2009 23:27
-
-
Save jtimberman/87950 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 | |
node[:gems_to_install].each do |pkg| | |
next if has_gem?(pkg[:name], pkg[:version].empty? ? nil : pkg[:version]) | |
gem_package pkg[:name] do | |
if pkg[:version] && !pkg[:version].empty? | |
version pkg[:version] | |
end | |
if pkg[:source] && !pkg[:source].empty? | |
source pkg[:source] | |
end | |
action :install | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment