1. Gem::
  2. RequestSet

class Gem::RequestSet

ARequestSet groups a request to activate a set of dependencies.

nokogiri =Gem::Dependency.new'nokogiri','~> 1.6'pg =Gem::Dependency.new'pg','~> 0.14'set =Gem::RequestSet.newnokogiri,pgrequests =set.resolveprequests.map {|r|r.full_name }#=> ["nokogiri-1.6.0", "mini_portile-0.5.1", "pg-0.17.0"]

Attributes

always_install[RW]

Array of gems to install even if already installed

dependencies[R]
development[RW]
development_shallow[RW]

Set to true if you want to install only direct development dependencies.

errors[R]

Errors fetching gems during resolution.

ignore_dependencies[RW]

When true, dependency resolution is not performed, only the requested gems are installed.

prerelease[RW]

If true, allow dependencies to match prerelease gems.

remote[RW]

When false no remote sets are used for resolving gems.

soft_missing[RW]

Treat missing dependencies as silent errors

source_set[R]

The set of source gems imported via load_gemdeps.

Public Class Methods

Source
# File lib/rubygems/request_set.rb, line 94definitialize(*deps)@dependencies =deps@always_install      = []@conservative        =false@dependency_names    = {}@development         =false@development_shallow =false@errors              = []@git_set             =nil@ignore_dependencies =false@install_dir         =Gem.dir@prerelease          =false@remote              =true@requests            = []@sets                = []@soft_missing        =false@sorted_requests     =nil@specs               =nil@vendor_set          =nil@source_set          =nilyieldselfifblock_given?end

Creates aRequestSet for a list ofGem::Dependency objects,deps. You can thenresolve andinstall the resolved list of dependencies.

nokogiri =Gem::Dependency.new'nokogiri','~> 1.6'pg =Gem::Dependency.new'pg','~> 0.14'set =Gem::RequestSet.newnokogiri,pg

Public Instance Methods

Source
# File lib/rubygems/request_set.rb, line 122defgem(name,*reqs)ifdep =@dependency_names[name]dep.requirement.concatreqselsedep =Gem::Dependency.newname,*reqs@dependency_names[name] =dep@dependencies<<dependend

Declare that a gem of namename withreqs requirements is needed.

Source
# File lib/rubygems/request_set.rb, line 135defimport(deps)@dependencies.concatdepsend

AdddepsGem::Dependency objects to the set.

Source
# File lib/rubygems/request_set.rb, line 146definstall(options,&block)# :yields: request, installerifdir =options[:install_dir]requests =install_intodir,false,options,&blockreturnrequestsend@prerelease =options[:prerelease]requests = []download_queue =Thread::Queue.new# Create a thread-safe list of gems to downloadsorted_requests.eachdo|req|download_queue<<reqend# Create N threads in a pool, have them download all the gemsthreads =Array.new(Gem.configuration.concurrent_downloads)do# When a thread pops this item, it knows to stop running. The symbol# is queued here so that there will be one symbol per thread.download_queue<<:stopThread.newdo# The pop method will block waiting for items, so the only way# to stop a thread from running is to provide a final item that# means the thread should stop.whilereq =download_queue.popbreakifreq==:stopreq.spec.downloadoptionsunlessreq.installed?endendend# Wait for all the downloads to finish before continuingthreads.each(&:value)# Install requested gems after they have been downloadedsorted_requests.eachdo|req|ifreq.installed?&&@always_install.none? {|spec|spec==req.spec.spec }req.spec.spec.build_extensionsyieldreq,nilifblock_given?nextendspec =beginreq.spec.installoptionsdo|installer|yieldreq,installerifblock_given?endrescueGem::RuntimeRequirementNotMetError=>esuggestion ="There are no versions of #{req.request} compatible with your Ruby & RubyGems"suggestion+=". Maybe try installing an older version of the gem you're looking for?"unless@always_install.include?(req.spec.spec)e.suggestion =suggestionraiseendrequests<<specendreturnrequestsifoptions[:gemdeps]install_hooksrequests,optionsrequestsend

Installs gems for thisRequestSet using theGem::Installeroptions.

If ablock is given an activationrequest andinstaller are yielded. Theinstaller will benil if a gem matching the request was already installed.

Source
# File lib/rubygems/request_set.rb, line 219definstall_from_gemdeps(options,&block)gemdeps =options[:gemdeps]@install_dir =options[:install_dir]||Gem.dir@prerelease  =options[:prerelease]@remote      =options[:domain]!=:local@conservative =trueifoptions[:conservative]gem_deps_api =load_gemdepsgemdeps,options[:without_groups],trueresolveifoptions[:explain]puts"Gems to install:"sorted_requests.eachdo|spec|puts"  #{spec.full_name}"endifGem.configuration.really_verbose@resolver.stats.displayendelseinstalled =installoptions,&blockifoptions.fetch:lock,truelockfile =Gem::RequestSet::Lockfile.buildself,gemdeps,gem_deps_api.dependencieslockfile.writeendinstalledendend

Installs from the gem dependencies files in the:gemdeps option inoptions, yielding to theblock as ininstall.

If:without_groups is given in theoptions, those groups in the gem dependencies file are not used. SeeGem::Installer for otheroptions.

Source
# File lib/rubygems/request_set.rb, line 295definstall_hooks(requests,options)specs =requests.mapdo|request|caserequestwhenGem::Resolver::ActivationRequestthenrequest.spec.specelserequestendendrequire_relative"dependency_installer"inst =Gem::DependencyInstaller.newoptionsinst.installed_gems.replacespecsGem.done_installing_hooks.eachdo|hook|hook.callinst,specsendunlessGem.done_installing_hooks.empty?end

Call hooks on installed gems

Source
# File lib/rubygems/request_set.rb, line 254definstall_into(dir,force =true,options = {})gem_home =ENV["GEM_HOME"]ENV["GEM_HOME"] =direxisting =force? []:specs_in(dir)existing.delete_if {|s|@always_install.include?s }dir =File.expand_pathdirinstalled = []options[:development] =falseoptions[:install_dir] =diroptions[:only_install_dir] =true@prerelease =options[:prerelease]sorted_requests.eachdo|request|spec =request.specifexisting.find {|s|s.full_name==spec.full_name }yieldrequest,nilifblock_given?nextendspec.installoptionsdo|installer|yieldrequest,installerifblock_given?endinstalled<<requestendinstall_hooksinstalled,optionsinstalledensureENV["GEM_HOME"] =gem_homeend
Source
# File lib/rubygems/request_set.rb, line 317defload_gemdeps(path,without_groups = [],installing =false)@git_set    =Gem::Resolver::GitSet.new@vendor_set =Gem::Resolver::VendorSet.new@source_set =Gem::Resolver::SourceSet.new@git_set.root_dir =@install_dirlock_file ="#{File.expand_path(path)}.lock"begintokenizer =Gem::RequestSet::Lockfile::Tokenizer.from_filelock_fileparser =tokenizer.make_parserself, []parser.parserescueErrno::ENOENTendgf =Gem::RequestSet::GemDependencyAPI.newself,pathgf.installing =installinggf.without_groups =without_groupsifwithout_groupsgf.loadend

Load a dependency management file.

Source
# File lib/rubygems/request_set.rb, line 384defresolve(set =Gem::Resolver::BestSet.new)@sets<<set@sets<<@git_set@sets<<@vendor_set@sets<<@source_setset =Gem::Resolver.compose_sets(*@sets)set.remote =@remoteset.prerelease =@prereleaseresolver =Gem::Resolver.new@dependencies,setresolver.development         =@developmentresolver.development_shallow =@development_shallowresolver.ignore_dependencies =@ignore_dependenciesresolver.soft_missing        =@soft_missingif@conservativeinstalled_gems = {}Gem::Specification.find_alldo|spec|      (installed_gems[spec.name]||= [])<<specendresolver.skip_gems =installed_gemsend@resolver =resolver@requests =resolver.resolve@errors =set.errors@requestsend

Resolve the requested dependencies and return anArray of Specification objects to be activated.

Source
# File lib/rubygems/request_set.rb, line 421defresolve_currentresolveGem::Resolver::CurrentSet.newend

Resolve the requested dependencies against the gems available viaGem.path and return anArray of Specification objects to be activated.

Source
# File lib/rubygems/request_set.rb, line 425defsorted_requests@sorted_requests||=strongly_connected_components.flattenend
Source
# File lib/rubygems/request_set.rb, line 429defspecs@specs||=@requests.map(&:full_spec)end
Source
# File lib/rubygems/request_set.rb, line 433defspecs_in(dir)Gem::Util.glob_files_in_dir("*.gemspec",File.join(dir,"specifications")).mapdo|g|Gem::Specification.loadgendend