def self.activate(gem, *version_requirements)
if version_requirements.empty? then
version_requirements = Gem::Requirement.default
end
unless gem.respond_to?(:name) and
gem.respond_to?(:version_requirements) then
gem = Gem::Dependency.new(gem, version_requirements)
end
matches = Gem.source_index.find_name(gem.name, gem.version_requirements)
report_activate_error(gem) if matches.empty?
if @loaded_specs[gem.name] then
existing_spec = @loaded_specs[gem.name]
unless matches.any? { |spec| spec.version == existing_spec.version } then
raise Gem::Exception,
"can't activate #{gem}, already activated #{existing_spec.full_name}]"
end
return false
end
spec = matches.last
return false if spec.loaded?
spec.loaded = true
@loaded_specs[spec.name] = spec
spec.dependencies.each do |dep_gem|
activate dep_gem
end
spec.require_paths.unshift spec.bindir if spec.bindir
require_paths = spec.require_paths.map do |path|
File.join spec.full_gem_path, path
end
sitelibdir = ConfigMap[:sitelibdir]
insert_index = load_path_insert_index
if insert_index then
$LOAD_PATH.insert(insert_index, *require_paths)
else
$LOAD_PATH.unshift(*require_paths)
end
return true
end