#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'rubygems' include Breakpoint gem_command = (RUBY_PLATFORM =~ /win32/) ? 'gem.bat' : 'sudo gem' puts "Loading application Gem configuration...\n" gem_config = open("#{RAILS_ROOT}/config/gems.yml") { |f| YAML.load(f.read) } if ARGV[0] == '-d' puts "Loading developer Gem configuration...\n" gem_config = gem_config + open("#{RAILS_ROOT}/config/developer_gems.yml") { |f| YAML.load(f.read) } end platform = 'ruby' gem_config.each do |gem, version| begin require_gem gem, version rescue Gem::LoadError => e puts "Gem #{gem} version #{version} not found, installing...\n" cmd = "#{gem_command} install #{gem} --include-dependencies --version '#{version}' " Open3.popen3(cmd) do | stdin, stdout, stderr | stdout.each_line do | line | if line =~ /\s(\d+).*\(#{platform}\)/ selection = $1.dup + "\n" puts "Multiple Gems available, selecting #$&" stdin.puts(selection) end end end if $? != 0 puts "An error occurred while installing gem #{gem}\n\n-- BEGIN GEM OUTPUT --\n\n" + output raise e end end end puts "All required gems are installed and available.\n" exit 0