/** * 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}"; } } }