require'rdoc/ri'### The directories where ri data lives.moduleRDoc::RI::Paths#:stopdoc:require'rbconfig'version=RbConfig::CONFIG['ruby_version']base=ifRbConfig::CONFIG.key?'ridir'thenFile.joinRbConfig::CONFIG['ridir'],versionelseFile.joinRbConfig::CONFIG['datadir'],'ri',versionendSYSDIR=File.joinbase,"system"SITEDIR=File.joinbase,"site"homedir=File.expand_path('~')||ENV['HOME']||ENV['USERPROFILE']||ENV['HOMEPATH']HOMEDIR=ifhomedirthenFile.joinhomedir,".rdoc"end#:startdoc:@gemdirs=nil### Iterates over each selected path yielding the directory and type.## Yielded types:# :system:: Where Ruby's ri data is stored. Yielded when +system+ is# true# :site:: Where ri for installed libraries are stored. Yielded when# +site+ is true. Normally no ri data is stored here.# :home:: ~/.ri. Yielded when +home+ is true.# :gem:: ri data for an installed gem. Yielded when +gems+ is true.# :extra:: ri data directory from the command line. Yielded for each# entry in +extra_dirs+defself.eachsystem,site,home,gems,*extra_dirs# :yields: directory, typeextra_dirs.eachdo|dir|yielddir,:extraendyieldSYSDIR,:systemifsystemyieldSITEDIR,:siteifsiteyieldHOMEDIR,:homeifhomegemdirs.eachdo|dir|yielddir,:gemendifgemsnilend### The latest installed gems' ri directoriesdefself.gemdirsreturn@gemdirsif@gemdirsrequire'rubygems'unlessdefined?(Gem)# HACK dup'd from Gem.latest_partials and friendsall_paths=[]all_paths=Gem.path.mapdo|dir|Dir[File.join(dir,'doc','*','ri')]end.flattenri_paths={}all_paths.eachdo|dir|base=File.basenameFile.dirname(dir)ifbase=~/(.*)-((\d+\.)*\d+)/thenname,version=$1,$2ver=Gem::Version.newversionifri_paths[name].nil?orver>ri_paths[name][0]thenri_paths[name]=[ver,dir]endendend@gemdirs=ri_paths.map{|k,v|v.last}.sortrescueLoadError@gemdirs=[]end### Returns existing directories from the selected documentation directories# as an Array.## See also ::eachdefself.path(system,site,home,gems,*extra_dirs)path=raw_pathsystem,site,home,gems,*extra_dirspath.select{|directory|File.directory?directory}end### Returns selected documentation directories including nonexistent# directories.## See also ::eachdefself.raw_path(system,site,home,gems,*extra_dirs)path=[]each(system,site,home,gems,*extra_dirs)do|dir,type|path<<direndpath.compactendend