Looks for a gem dependency file at path and activates the gems in the
file if found. If the file is not found an ArgumentError is raised.
If path is not given the
RUBYGEMS_GEMDEPS environment variable is used, but if no file is found no
exception is raised.
If ‘-’ is given for path
RubyGems searches up from the current working directory for gem dependency
files (gem.deps.rb, Gemfile, Isolate) and activates the gems in the first
one found.
You can run this automatically when rubygems starts. To enable, set the
RUBYGEMS_GEMDEPS environment variable to either the path of your gem dependencies file or
“-” to auto-discover in parent directories.
NOTE: Enabling automatic discovery on multiuser systems can lead to
execution of arbitrary code when used from directories outside your
control.
# File lib/rubygems.rb, line 1162
def self.use_gemdeps path = nil
raise_exception = path
path ||= ENV['RUBYGEMS_GEMDEPS']
return unless path
path = path.dup
if path == "-" then
Gem::Util.traverse_parents Dir.pwd do |directory|
dep_file = GEM_DEP_FILES.find { |f| File.file?(f) }
next unless dep_file
path = File.join directory, dep_file
break
end
end
path.untaint
unless File.file? path then
return unless raise_exception
raise ArgumentError, "Unable to find gem dependencies file at #{path}"
end
if USE_BUNDLER_FOR_GEMDEPS
ENV["BUNDLE_GEMFILE"] ||= File.expand_path(path)
require 'rubygems/user_interaction'
Gem::DefaultUserInteraction.use_ui(ui) do
require "bundler"
@gemdeps = Bundler.setup
Bundler.ui = nil
@gemdeps.requested_specs.map(&:to_spec).sort_by(&:name)
end
else
rs = Gem::RequestSet.new
@gemdeps = rs.load_gemdeps path
rs.resolve_current.map do |s|
s.full_spec.tap(&:activate)
end
end
rescue => e
case e
when Gem::LoadError, Gem::UnsatisfiableDependencyError, (defined?(Bundler::GemNotFound) ? Bundler::GemNotFound : Gem::LoadError)
warn e.message
warn "You may need to `gem install -g` to install missing gems"
warn ""
else
raise
end
end