Skip to content

Instantly share code, notes, and snippets.

@jtimberman
Created March 30, 2009 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtimberman/87950 to your computer and use it in GitHub Desktop.
Save jtimberman/87950 to your computer and use it in GitHub Desktop.
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