/**
  * Make sure the compass and sass gems are up to date.
  *
  * If the gems are not present, the system will install them automatically, 
  * but won't update them after that for speeds sake. Call this from sake to 
  * ensure you've got the most up-to-date version.
  * 
  * Designed to be called as a sake command:
  * <code>
  * sapphire/sake dev/compass/updategems
  * </code>
  * 
  * @param bool $verbose - use Compass::$errors_are_errors = false to suppress.
  * 
  */
 public function updategems($verbose = false)
 {
     foreach (self::$required_gems[self::$sass_version] as $gem => $version) {
         if (is_numeric($gem)) {
             $gem = $version;
             $version = null;
         }
         if ($error = Rubygems::require_gem($gem, $version, true)) {
             echo $error;
         }
     }
     if ($verbose) {
         echo "\nGem update succesfull\n";
     }
 }
    /**
     * Make sure a gem is available
     *
     * @param $gem string - the name of the gem to install
     * @param $version string - the specific version to install
     * @param $tryupdating bool - if the gem is present, check for update? (hits the internet, so slow)
     *
     * @return null | string - an error string on error, nothing on success
     */
    public static function require_gem($gem, $version = null, $tryupdating = false)
    {
        // Check that ruby exists
        if (self::$ruby_ok === null) {
            self::$ruby_ok = (bool) `which ruby`;
        }
        if (!self::$ruby_ok) {
            return 'Ruby isn\'t present. The "ruby" command needs to be in the webserver\'s path';
        }
        // Check that rubygems exists and is a good enough version
        if (self::$gem_version_ok === null) {
            $code = self::_run('gem environment version', $ver, $err);
            if ($code !== 0) {
                return 'Ruby is present, but there was a problem accessing the \\
					current rubygems version - is rubygems available? The "gem" \\
					command needs to be in the webserver\'s path.';
            }
            $vers = explode('.', $ver);
            self::$gem_version_ok = ($vers[0] >= 1 && $vers[1] >= 2 or $vers[0] >= 2);
        }
        if (!self::$gem_version_ok) {
            return "Rubygems is too old. You have version {$ver}, but we need at \\\n\t\t\t\tleast version 1.2. Please upgrade.";
        }
        $veropt = $version ? "-v '{$version}'" : '';
        // See if the gem exists. If not, try adding it
        self::_run("gem list -i {$gem} {$veropt}", $out, $err);
        if (trim($out) != 'true' || $tryupdating) {
            $code = self::_run("gem install {$gem} {$veropt} --no-rdoc --no-ri", $out, $err);
            if ($code !== 0) {
                return "Could not install required gem {$gem}. Either manually \\\n\t\t\t\t\tinstall, or repair error. Error message was: {$err}";
            }
        }
    }