module Gem

RubyGems is the Ruby standard for publishing and managing third party libraries.

For user documentation, see:

For gem developer documentation see:

Further RubyGems documentation can be found at:

RubyGems Plugins

RubyGems will load plugins in the latest version of each installed gem or $LOAD_PATH. Plugins must be named ‘rubygems_plugin’ (.rb, .so, etc) and placed at the root of your gem’s require_path. Plugins are installed at a special location and loaded on boot.

For an example plugin, see theGraph gem which adds agem graph command.

RubyGems Defaults, Packaging

RubyGems defaults are stored in lib/rubygems/defaults.rb. If you’re packaging RubyGems or implementing Ruby you can change RubyGems’ defaults.

For RubyGems packagers, provide lib/rubygems/defaults/operating_system.rb and override any defaults from lib/rubygems/defaults.rb.

For Ruby implementers, provide lib/rubygems/defaults/#{RUBY_ENGINE}.rb and override any defaults from lib/rubygems/defaults.rb.

If you need RubyGems to perform extra work on install or uninstall, your defaults override file can set pre/post install and uninstall hooks. SeeGem::pre_install,Gem::pre_uninstall,Gem::post_install,Gem::post_uninstall.

Bugs

You can submit bugs to theRubyGems bug tracker on GitHub

Credits

RubyGems is currently maintained by Eric Hodel.

RubyGems was originally developed at RubyConf 2003 by:

Contributors:

(If your name is missing, PLEASE let us know!)

License

SeeLICENSE.txt for permissions.

Thanks!

-The RubyGems Team

Provides 3 methods for declaring when something is going away.

+deprecate(name, repl, year, month)+:

Indicate something may be removed on/after a certain date.

+rubygems_deprecate(name, replacement=:none)+:

Indicate something will be removed in the next major RubyGems version,and (optionally) a replacement for it.

rubygems_deprecate_command:

Indicate a RubyGems command (in +lib/rubygems/commands/*.rb+) will beremoved in the next RubyGems version.

Also providesskip_during for temporarily turning off deprecation warnings. This is intended to be used in the test suite, so deprecation warnings don’t cause test failures if you need to make sure stderr is otherwise empty.

Example usage ofdeprecate andrubygems_deprecate:

classLegacydefself.some_class_method# ...enddefsome_instance_method# ...enddefsome_old_method# ...endextendGem::Deprecatedeprecate:some_instance_method,"X.z",2011,4rubygems_deprecate:some_old_method,"Modern#some_new_method"class<<selfextendGem::Deprecatedeprecate:some_class_method,:none,2011,4endend

Example usage ofrubygems_deprecate_command:

classGem::Commands::QueryCommand<Gem::CommandextendGem::Deprecaterubygems_deprecate_command# ...end

Example usage ofskip_during:

classTestSomething<Gem::Testcasedeftest_some_thing_with_deprecationsGem::Deprecate.skip_duringdoactual_stdout,actual_stderr =capture_outputdoGem.something_deprecatedendassert_emptyactual_stdoutassert_equal(expected,actual_stderr)endendend

Constants

DEFAULT_HOST
DEFAULT_SOURCE_DATE_EPOCH

The default value for SOURCE_DATE_EPOCH if not specified. We want a date after 1980-01-01, to prevent issues with Zip files. This particular timestamp is for 1980-01-02 00:00:00 GMT.

GEM_DEP_FILES
LOADED_SPECS_MUTEX
MARSHAL_SPEC_DIR

Location ofMarshal quick gemspecs on remote repositories

RDoc
REPOSITORY_DEFAULT_GEM_SUBDIRECTORIES

Subdirectories in a gem repository for default gems

REPOSITORY_SUBDIRECTORIES

Subdirectories in a gem repository

RUBYGEMS_DIR
VERSION
WIN_PATTERNS

AnArray of Regexps that match windows Ruby platforms.

Attributes

disable_system_update_message[RW]

RubyGems distributors (like operating system package managers) can disable RubyGems update by setting this to error message printed to end-users on gem update –system instead of actual update.

discover_gems_on_require[RW]

Whether RubyGems should enhance builtin ‘require` to automatically check whether the path required is present in installed gems, and automatically activate them and add them to `$LOAD_PATH`.

done_installing_hooks[R]

The list of hooks to be run afterGem::DependencyInstaller installs a set of gems

gemdeps[R]

GemDependencyAPI object, which is set when .use_gemdeps is called. This contains all the information from the Gemfile.

loaded_specs[R]

Hash of loadedGem::Specification keyed by name

post_build_hooks[R]

The list of hooks to be run afterGem::Installer#install extracts files and builds extensions

post_install_hooks[R]

The list of hooks to be run afterGem::Installer#install completes installation

post_reset_hooks[R]

The list of hooks to be run afterGem::Specification.reset is run.

post_uninstall_hooks[R]

The list of hooks to be run afterGem::Uninstaller#uninstall completes installation

pre_install_hooks[R]

The list of hooks to be run beforeGem::Installer#install does any work

pre_reset_hooks[R]

The list of hooks to be run beforeGem::Specification.reset is run.

pre_uninstall_hooks[R]

The list of hooks to be run beforeGem::Uninstaller#uninstall does any work

Public Class Methods

Source
# File lib/rubygems.rb, line 281defself.activate_and_load_bin_path(name,exec_name =nil,*requirements)spec =find_and_activate_spec_for_exename,exec_name,requirementsifspec.name=="bundler"# Old versions of Bundler need a workaround to support nested `bundle# exec` invocations by overriding `Gem.activate_bin_path`. However,# RubyGems now uses this new `Gem.activate_and_load_bin_path` helper in# binstubs, which is of course not overridden in Bundler since it didn't# exist at the time. So, include the override here to workaround that.loadENV["BUNDLE_BIN_PATH"]ifENV["BUNDLE_BIN_PATH"]&&spec.version<="2.5.22"# Make sure there's no version of Bundler in `$LOAD_PATH` that's different# from the version we just activated. If that was the case (it happens# when testing Bundler from ruby/ruby), we would load Bundler extensions# to RubyGems from the copy in `$LOAD_PATH` but then load the binstub from# an installed copy, causing those copies to be mixed and yet more# redefinition warnings.#require_path =$LOAD_PATH.resolve_feature_path("bundler").last.delete_suffix("/bundler.rb")Gem.load_bundler_extensions(spec.version)ifspec.full_require_paths.include?(require_path)endloadspec.bin_file(exec_name)end

Find and load the full path to the executable for gemname. If theexec_name is not given, an exception will be raised, otherwise the specified executable’s path is returned.requirements allows you to specify specific gem versions.

A side effect of this method is that it will activate the gem that contains the executable.

This method shouldonly be used in bin stub files.

Source
# File lib/rubygems.rb, line 624defself.activated_gem_paths@activated_gem_paths||=0end

The number of paths in the +$LOAD_PATH+ from activated gems. Used to prioritize-I andENV['RUBYLIB'] entries duringrequire.

Source
# File lib/rubygems.rb, line 631defself.add_to_load_path(*paths)@activated_gem_paths =activated_gem_paths+paths.size# gem directories must come after -I and ENV['RUBYLIB']$LOAD_PATH.insert(Gem.load_path_insert_index,*paths)end

Add a list of paths to the $LOAD_PATH at the proper place.

Source
# File lib/rubygems.rb, line 229defself.bin_path(name,exec_name =nil,*requirements)requirements =Gem::Requirement.defaultifrequirements.empty?find_spec_for_exe(name,exec_name,requirements).bin_fileexec_nameend

Find the full path to the executable for gemname. If theexec_name is not given, an exception will be raised, otherwise the specified executable’s path is returned.requirements allows you to specify specific gem versions.

Source
# File lib/rubygems.rb, line 324defself.binary_mode"rb"end

The mode needed to read a file as straight binary.

Source
# File lib/rubygems.rb, line 331defself.bindir(install_dir =Gem.dir)returnFile.joininstall_dir,"bin"unlessinstall_dir.to_s==Gem.default_dir.to_sGem.default_bindirend

The path where gem executables are to be installed.

Source
# File lib/rubygems/defaults.rb, line 147defself.cache_home@cache_home||=ENV["XDG_CACHE_HOME"]||File.join(Gem.user_home,".cache")end

The path to standard location of the user’s cache directory.

Source
# File lib/rubygems.rb, line 1317defclear_default_specs@path_to_default_spec_map.clearend

Clear default gem related variables. It is for test

Source
# File lib/rubygems.rb, line 349defself.clear_paths@paths         =nil@user_home     =nilGem::Specification.resetGem::Security.resetifdefined?(Gem::Security)end

Reset thedir andpath values. The next timedir orpath is requested, the values will be calculated from scratch. This is mainly used by the unit tests to provide test isolation.

Source
# File lib/rubygems/defaults.rb, line 133defself.config_file@config_file||=find_config_fileend

The path to standard location of the user’s .gemrc file.

Source
# File lib/rubygems/defaults.rb, line 114defself.config_home@config_home||=ENV["XDG_CONFIG_HOME"]||File.join(Gem.user_home,".config")end

The path to standard location of the user’s configuration directory.

Source
# File lib/rubygems.rb, line 359defself.configuration@configuration||=Gem::ConfigFile.new []end

The standard configuration object for gems.

Source
# File lib/rubygems.rb, line 367defself.configuration=(config)@configuration =configend

Use the given configuration object (which implements theConfigFile protocol) as the standard configuration object.

Source
# File lib/rubygems/defaults.rb, line 154defself.data_home@data_home||=ENV["XDG_DATA_HOME"]||File.join(Gem.user_home,".local","share")end

The path to standard location of the user’s data directory.

Source
# File lib/rubygems/defaults.rb, line 204defself.default_bindirRbConfig::CONFIG["bindir"]end

The default directory for binaries

Source
# File lib/rubygems/defaults.rb, line 228defself.default_cert_pathdefault_cert_path =File.joinGem.user_home,".gem","gem-public_cert.pem"unlessFile.exist?(default_cert_path)default_cert_path =File.joinGem.data_home,"gem","gem-public_cert.pem"enddefault_cert_pathend

The default signing certificate chain path

Source
# File lib/rubygems/defaults.rb, line 37defself.default_dir@default_dir||=File.join(RbConfig::CONFIG["rubylibprefix"],"gems",RbConfig::CONFIG["ruby_version"])end

Default home directory path to be used if an alternate value is not specified in the environment

Source
# File lib/rubygems/defaults.rb, line 186defself.default_exec_formatexec_format =beginRbConfig::CONFIG["ruby_install_name"].sub("ruby","%s")rescueStandardError"%s"endunlessexec_format.include?("%s")raiseGem::Exception,"[BUG] invalid exec_format #{exec_format.inspect}, no %s"endexec_formatend

Deduce Ruby’s –program-prefix and –program-suffix from its install name

Source
# File lib/rubygems/defaults.rb, line 48defself.default_ext_dir_for(base_dir)nilend

Returns binary extensions dir for specified RubyGems base dir or nil if such directory cannot be determined.

By default, the binary extensions are located side by side with their Ruby counterparts, therefore nil is returned

Source
# File lib/rubygems/defaults.rb, line 215defself.default_key_pathdefault_key_path =File.joinGem.user_home,".gem","gem-private_key.pem"unlessFile.exist?(default_key_path)default_key_path =File.joinGem.data_home,"gem","gem-private_key.pem"enddefault_key_pathend

The default signing key path

Source
# File lib/rubygems/defaults.rb, line 175defself.default_pathpath = []path<<user_dirifuser_home&&File.exist?(user_home)path<<default_dirpath<<vendor_dirifvendor_dir&&File.directory?(vendor_dir)pathend

Default gem load path

Source
# File lib/rubygems/defaults.rb, line 55defself.default_rubygems_dirsnil# default to standard layoutend

Paths where RubyGems’ .rb files and bin files are installed

Source
# File lib/rubygems/defaults.rb, line 15defself.default_sources@default_sources||=%w[https://rubygems.org/]end

AnArray of the default sources that come with RubyGems

Source
# File lib/rubygems/defaults.rb, line 23defself.default_spec_cache_dirdefault_spec_cache_dir =File.joinGem.user_home,".gem","specs"unlessFile.exist?(default_spec_cache_dir)default_spec_cache_dir =File.joinGem.cache_home,"gem","specs"enddefault_spec_cache_dirend

Default spec directory path to be used if an alternate value is not specified in the environment

Source
# File lib/rubygems/defaults.rb, line 62defself.default_specifications_dir@default_specifications_dir||=File.join(Gem.default_dir,"specifications","default")end

Path to specification files of default gems.

Source
# File lib/rubygems.rb, line 374defself.deflate(data)require"zlib"Zlib::Deflate.deflatedataend

AZlib::Deflate.deflate wrapper

Source
# File lib/rubygems.rb, line 422defself.dirpaths.homeend

The path where gems are to be installed.

Source
# File lib/rubygems.rb, line 759defself.done_installing(&hook)@done_installing_hooks<<hookend

Adds a post-installs hook that will be passed aGem::DependencyInstaller and a list of installed specifications whenGem::DependencyInstaller#install is complete

Source
# File lib/rubygems.rb, line 1040defself.dynamic_library_suffixes@dynamic_library_suffixes||=suffixes- [".rb"]end

Suffixes for dynamic library require-able paths.

Source
# File lib/rubygems.rb, line 473defself.ensure_default_gem_subdirectories(dir =Gem.dir,mode =nil)ensure_subdirectories(dir,mode,REPOSITORY_DEFAULT_GEM_SUBDIRECTORIES)end

Quietly ensure theGem directorydir contains all the proper subdirectories for handling default gems. If we can’t create a directory due to a permission problem, then we will silently continue.

Ifmode is given, missing directories are created with this mode.

World-writable directories will never be created.

Source
# File lib/rubygems.rb, line 460defself.ensure_gem_subdirectories(dir =Gem.dir,mode =nil)ensure_subdirectories(dir,mode,REPOSITORY_SUBDIRECTORIES)end

Quietly ensure theGem directorydir contains all the proper subdirectories. If we can’t create a directory due to a permission problem, then we will silently continue.

Ifmode is given, missing directories are created with this mode.

World-writable directories will never be created.

Source
# File lib/rubygems.rb, line 908defself.env_requirement(gem_name)@env_requirements_by_name||= {}@env_requirements_by_name[gem_name]||=beginreq =ENV["GEM_REQUIREMENT_#{gem_name.upcase}"]||">= 0"Gem::Requirement.create(req)endend
Source
# File lib/rubygems/defaults.rb, line 121defself.find_config_filegemrc =File.joinGem.user_home,".gemrc"ifFile.exist?gemrcgemrcelseFile.joinGem.config_home,"gem","gemrc"endend

Finds the user’s config file

Source
# File lib/rubygems.rb, line 1302deffind_default_spec(path)@path_to_default_spec_map[path]end

Find aGem::Specification of default gem frompath

Source
# File lib/rubygems.rb, line 524defself.find_files(glob,check_load_path =true)files = []files =find_files_from_load_pathglobifcheck_load_pathgem_specifications =@gemdeps?Gem.loaded_specs.values:Gem::Specification.stubsfiles.concatgem_specifications.flat_map {|spec|spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}")  }# $LOAD_PATH might contain duplicate entries or reference# the spec dirs directly, so we prune.files.uniq!ifcheck_load_pathfilesend

Returns a list of paths matchingglob that can be used by a gem to pick up features from other gems. For example:

Gem.find_files('rdoc/discover').eachdo|path|loadpathend

ifcheck_load_path is true (the default), thenfind_files also searches $LOAD_PATH for files as well as gems.

Note thatfind_files will return all files even if they are from different versions of the same gem. See alsofind_latest_files

Source
# File lib/rubygems.rb, line 561defself.find_latest_files(glob,check_load_path =true)files = []files =find_files_from_load_pathglobifcheck_load_pathfiles.concatGem::Specification.latest_specs(true).flat_map {|spec|spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}")  }# $LOAD_PATH might contain duplicate entries or reference# the spec dirs directly, so we prune.files.uniq!ifcheck_load_pathfilesend

Returns a list of paths matchingglob from the latest gems that can be used by a gem to pick up features from other gems. For example:

Gem.find_latest_files('rdoc/discover').eachdo|path|loadpathend

ifcheck_load_path is true (the default), thenfind_latest_files also searches $LOAD_PATH for files as well as gems.

Unlikefind_files,find_latest_files will return only files from the latest version of a gem.

Source
# File lib/rubygems.rb, line 1309deffind_unresolved_default_spec(path)default_spec =@path_to_default_spec_map[path]default_specifdefault_spec&&loaded_specs[default_spec.name]!=default_specend

Find an unresolvedGem::Specification of default gem frompath

Source
# File lib/rubygems.rb, line 214defself.finish_resolve(request_set =Gem::RequestSet.new)request_set.importGem::Specification.unresolved_deps.valuesrequest_set.importGem.loaded_specs.values.map {|s|Gem::Dependency.new(s.name,s.version) }request_set.resolve_current.eachdo|s|s.full_spec.activateendend
Source
# File lib/rubygems.rb, line 1098defself.freebsd_platform?RbConfig::CONFIG["host_os"].to_s.include?("bsd")end

Is this platform FreeBSD

Source
# File lib/rubygems.rb, line 596defself.host@host||=Gem::DEFAULT_HOSTend

Get the default RubyGems API host. This is normallyhttps://rubygems.org.

Source
# File lib/rubygems.rb, line 602defself.host=(host)@host =hostend

Set the default RubyGems API host.

Source
# File lib/rubygems.rb, line 585defself.install(name,version =Gem::Requirement.default,*options)require_relative"rubygems/dependency_installer"inst =Gem::DependencyInstaller.new(*options)inst.installname,versioninst.installed_gemsend

Top level install helper method. Allows you to install gems interactively:

% irb>> Gem.install "minitest"Fetching: minitest-5.14.0.gem (100%)=> [#<Gem::Specification:0x1013b4528 @name="minitest", ...>]
Source
# File lib/rubygems.rb, line 1084defself.java_platform?RUBY_PLATFORM=="java"end

Is this a java platform?

Source
# File lib/rubygems.rb, line 933defself.latest_rubygems_versionlatest_version_for("rubygems-update")||raise("Can't find 'rubygems-update' in any repo. Check `gem source list`.")end

Returns the latest release version of RubyGems.

Source
# File lib/rubygems.rb, line 920defself.latest_spec_for(name)dependency   =Gem::Dependency.newnamefetcher      =Gem::SpecFetcher.fetcherspec_tuples, =fetcher.spec_for_dependencydependencyspec, =spec_tuples.lastspecend

Returns the latest release-version specification for the gemname.

Source
# File lib/rubygems.rb, line 941defself.latest_version_for(name)latest_spec_for(name)&.versionend

Returns the version of the latest release-version of gemname

Source
# File lib/rubygems.rb, line 668defself.load_bundler_extensions(version)returnunlessversion<="2.6.9"previous_platforms = {}platform_const_list = ["JAVA","MSWIN","MSWIN64","MINGW","X64_MINGW_LEGACY","X64_MINGW","UNIVERSAL_MINGW","WINDOWS","X64_LINUX","X64_LINUX_MUSL"]platform_const_list.eachdo|platform|previous_platforms[platform] =Gem::Platform.const_get(platform)Gem::Platform.send(:remove_const,platform)endrequire"bundler/rubygems_ext"platform_const_list.eachdo|platform|Gem::Platform.send(:remove_const,platform)ifGem::Platform.const_defined?(platform)Gem::Platform.const_set(platform,previous_platforms[platform])endend

LoadBundler extensions to RubyGems, making sure to avoid redefinition warnings in platform constants

Source
# File lib/rubygems.rb, line 1133defself.load_env_pluginsload_plugin_filesfind_files_from_load_path("rubygems_plugin")end

Find all ‘rubygems_plugin’ files in $LOAD_PATH and load them

Source
# File lib/rubygems.rb, line 610defself.load_path_insert_index$LOAD_PATH.each_with_indexdo|path,i|returniifpath.instance_variable_defined?(:@gem_prelude_index)endindex =$LOAD_PATH.indexRbConfig::CONFIG["sitelibdir"]index||0end

The index to insert activated gem paths into the $LOAD_PATH. The activated gem’s paths are inserted before site lib directory by default.

Source
# File lib/rubygems.rb, line 1124defself.load_pluginsGem.path.eachdo|gem_path|load_plugin_filesGem::Util.glob_files_in_dir("*#{Gem.plugin_suffix_pattern}",plugindir(gem_path))endend

Find rubygems plugin files in the standard location and load them

Source
# File lib/rubygems.rb, line 656defself.load_safe_marshalreturnif@safe_marshal_loadedrequire_relative"rubygems/safe_marshal"@safe_marshal_loaded =trueend
Source
# File lib/rubygems.rb, line 643defself.load_yamlreturnif@yaml_loadedrequire"psych"require_relative"rubygems/psych_tree"require_relative"rubygems/safe_yaml"@yaml_loaded =trueend

LoadsYAML, preferringPsych

Source
# File lib/rubygems.rb, line 702defself.location_of_caller(depth =1)caller[depth]=~/(.*?):(\d+).*?$/ifile =$1lineno =$2.to_i  [file,lineno]end

The file name and line number of the caller of the caller of this method.

depth is how many layers up the call stack it should go.

e.g.,

def a;Gem.location_of_caller; end a #=> [“x.rb”, 2] # (it’ll vary depending on file name and line number)

def b; c; end def c;Gem.location_of_caller(2); end b #=> [“x.rb”, 6] # (it’ll vary depending on file name and line number)

Source
# File lib/rubygems.rb, line 713defself.marshal_version"#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}"end

The version of theMarshal format for your Ruby.

Source
# File lib/rubygems.rb, line 206defself.needsrs =Gem::RequestSet.newyieldrsfinish_resolversend
Source
# File lib/rubygems.rb, line 849defself.open_file(path,flags,&block)File.open(path,flags,&block)end

Open a file with given flags

Source
# File lib/rubygems.rb, line 867defself.open_file_with_flock(path,&block)# read-write mode is used rather than read-only in order to support NFSmode =IO::RDWR|IO::APPEND|IO::CREAT|IO::BINARYmode|=IO::SHARE_DELETEifIO.const_defined?(:SHARE_DELETE)File.open(path,mode)do|io|begin# Try to get a lock without blocking.# If we do, the file is locked.# Otherwise, explain why we're waiting and get a lock, but block this time.ifio.flock(File::LOCK_EX|File::LOCK_NB)!=0warn"Waiting for another process to let go of lock: #{path}"io.flock(File::LOCK_EX)endio.puts(Process.pid)rescueErrno::ENOSYS,Errno::ENOTSUPendyieldioendend

Open a file with given flags, and protect access with flock

Source
# File lib/rubygems.rb, line 856defself.open_file_with_lock(path,&block)file_lock ="#{path}.lock"open_file_with_flock(file_lock,&block)ensurerequire"fileutils"FileUtils.rm_ffile_lockend

Open a file with given flags, and protect access with a file lock

Source
# File lib/rubygems/defaults.rb, line 286defself.operating_system_defaults  {}end

Default options for gem commands for Ruby packagers.

The options here should be structured as an array of string “gem” command names as keys and a string of the default options as values.

Example:

def self.operating_system_defaults

{'install'=>'--no-rdoc --no-ri --env-shebang','update'=>'--no-rdoc --no-ri --env-shebang'}

end

Source
# File lib/rubygems.rb, line 426defself.pathpaths.pathend
Source
# File lib/rubygems/defaults.rb, line 168defself.path_separatorFile::PATH_SEPARATORend

HowStringGem paths should be split. Overridable for esoteric platforms.

Source
# File lib/rubygems.rb, line 382defself.paths@paths||=Gem::PathSupport.new(ENV)end

Retrieve thePathSupport object that RubyGems uses to lookup files.

Source
# File lib/rubygems.rb, line 392defself.paths=(env)clear_pathstarget = {}env.each_pairdo|k,v|casekwhen"GEM_HOME","GEM_PATH","GEM_SPEC_CACHE"casevwhennil,Stringtarget[k] =vwhenArrayunlessGem::Deprecate.skipwarn<<-EOWARNArray values in the parameter to `Gem.paths=` are deprecated.Please use a String or nil.An Array (#{env.inspect}) was passed in from #{caller[3]}            EOWARNendtarget[k] =v.joinFile::PATH_SEPARATORendelsetarget[k] =vendend@paths =Gem::PathSupport.newENV.to_hash.merge(target)Gem::Specification.dirs =@paths.pathend

Initialize the filesystem paths to use fromenv.env is a hash-like object (typicallyENV) that is queried for ‘GEM_HOME’, ‘GEM_PATH’, and ‘GEM_SPEC_CACHE’ Keys for theenv hash should be Strings, and values of the hash should be Strings ornil.

Source
# File lib/rubygems/defaults.rb, line 305defself.platform_defaults  {}end

Default options for gem commands for Ruby implementers.

The options here should be structured as an array of string “gem” command names as keys and a string of the default options as values.

Example:

def self.platform_defaults

{'install'=>'--no-rdoc --no-ri --env-shebang','update'=>'--no-rdoc --no-ri --env-shebang'}

end

Source
# File lib/rubygems.rb, line 727defself.platforms@platforms||= []if@platforms.empty?@platforms = [Gem::Platform::RUBY,Gem::Platform.local]end@platformsend

Array of platforms this RubyGems supports.

Source
# File lib/rubygems.rb, line 720defself.platforms=(platforms)@platforms =platformsend

Set array of platforms this RubyGems supports (primarily for testing).

Source
# File lib/rubygems.rb, line 1013defself.plugin_suffix_pattern@plugin_suffix_pattern||="_plugin#{suffix_pattern}"end

Glob pattern for require-able plugin suffixes.

Source
# File lib/rubygems.rb, line 1020defself.plugin_suffix_regexp@plugin_suffix_regexp||=/_plugin#{suffix_regexp}\z/end

Regexp for require-able plugin suffixes.

Source
# File lib/rubygems.rb, line 340defself.plugindir(install_dir =Gem.dir)File.joininstall_dir,"plugins"end

The path were rubygems plugins are to be installed.

Source
# File lib/rubygems.rb, line 742defself.post_build(&hook)@post_build_hooks<<hookend

Adds a post-build hook that will be passed anGem::Installer instance whenGem::Installer#install is called. The hook is called after the gem has been extracted and extensions have been built but before the executables or gemspec has been written. If the hook returnsfalse then the gem’s files will be removed and the install will be aborted.

Source
# File lib/rubygems.rb, line 750defself.post_install(&hook)@post_install_hooks<<hookend

Adds a post-install hook that will be passed anGem::Installer instance whenGem::Installer#install is called

Source
# File lib/rubygems.rb, line 767defself.post_reset(&hook)@post_reset_hooks<<hookend

Adds a hook that will get run afterGem::Specification.reset is run.

Source
# File lib/rubygems.rb, line 776defself.post_uninstall(&hook)@post_uninstall_hooks<<hookend

Adds a post-uninstall hook that will be passed aGem::Uninstaller instance and the spec that was uninstalled whenGem::Uninstaller#uninstall is called

Source
# File lib/rubygems.rb, line 785defself.pre_install(&hook)@pre_install_hooks<<hookend

Adds a pre-install hook that will be passed anGem::Installer instance whenGem::Installer#install is called. If the hook returnsfalse then the install will be aborted.

Source
# File lib/rubygems.rb, line 793defself.pre_reset(&hook)@pre_reset_hooks<<hookend

Adds a hook that will get run beforeGem::Specification.reset is run.

Source
# File lib/rubygems.rb, line 802defself.pre_uninstall(&hook)@pre_uninstall_hooks<<hookend

Adds a pre-uninstall hook that will be passed anGem::Uninstaller instance and the spec that will be uninstalled whenGem::Uninstaller#uninstall is called

Source
# File lib/rubygems.rb, line 811defself.prefixprefix =File.dirnameRUBYGEMS_DIRifprefix!=File.expand_path(RbConfig::CONFIG["sitelibdir"])&&prefix!=File.expand_path(RbConfig::CONFIG["libdir"])&&File.basename(RUBYGEMS_DIR)=="lib"prefixendend

The directory prefix this RubyGems was installed at. If your prefix is in a standard location (ie, rubygems is installed where you’d expect it to be), then prefix returns nil.

Source
# File lib/rubygems/rdoc.rb, line 13defself.rdoc_hooks_defined_via_plugin?Gem::Version.new(::RDoc::VERSION)>=Gem::Version.new("6.9.0")end

Returns whether RDoc defines its own install hooks through a RubyGems plugin. This and whatever is guarded by it can be removed once no supported Ruby ships with RDoc older than 6.9.0.

Source
# File lib/rubygems.rb, line 831defself.read_binary(path)File.binread(path)end

Safely read a file in binary mode on all platforms.

Source
# File lib/rubygems.rb, line 824defself.refreshGem::Specification.resetend

Refresh available gems from disk.

Source
# File lib/rubygems.rb, line 1277defregister_default_spec(spec)extended_require_paths =spec.require_paths.map {|f|f+"/" }new_format =extended_require_paths.any? {|path|spec.files.any? {|f|f.start_with?path } }ifnew_formatprefix_group =extended_require_paths.join("|")prefix_pattern =/^(#{prefix_group})/endspec.files.eachdo|file|ifnew_formatfile =file.sub(prefix_pattern,"")nextunless$~endspec.activateifalready_loaded?(file)@path_to_default_spec_map[file] =spec@path_to_default_spec_map[file.sub(suffix_regexp,"")] =specendend

Register aGem::Specification for default gem.

Two formats for the specification are supported:

  • MRI 2.0 style, where spec.files contains unprefixed require names. The spec’s filenames will be registered as-is.

  • New style, where spec.files contains files prefixed with paths from spec.require_paths. The prefixes are stripped before registering the spec’s filenames. Unprefixed files are omitted.

Source
# File lib/rubygems.rb, line 891defself.rubyif@ruby.nil?@ruby =RbConfig.ruby@ruby ="\"#{@ruby}\""if/\s/.match?(@ruby)end@rubyend

The path to the running Ruby interpreter.

Source
# File lib/rubygems.rb, line 904defself.ruby_api_version@ruby_api_version||=target_rbconfig["ruby_version"].dupend

Returns aString containing the API compatibility version of Ruby

Source
# File lib/rubygems/defaults.rb, line 208defself.ruby_engineRUBY_ENGINEend
Source
# File lib/rubygems.rb, line 948defself.ruby_versionreturn@ruby_versionifdefined?@ruby_versionversion =RUBY_VERSION.dupifRUBY_PATCHLEVEL==-1ifRUBY_ENGINE=="ruby"desc =RUBY_DESCRIPTION[/\Aruby #{Regexp.quote(RUBY_VERSION)}([^ ]+) /,1]elsedesc =RUBY_DESCRIPTION[/\A#{RUBY_ENGINE} #{Regexp.quote(RUBY_ENGINE_VERSION)} \(#{RUBY_VERSION}([^ ]+)\) /,1]endversion<<".#{desc}"ifdescend@ruby_version =Gem::Version.newversionend

AGem::Version for the currently running Ruby.

Source
# File lib/rubygems.rb, line 967defself.rubygems_versionreturn@rubygems_versionifdefined?@rubygems_version@rubygems_version =Gem::Version.newGem::VERSIONend

AGem::Version for the currently running RubyGems

Source
# File lib/rubygems.rb, line 444defself.set_target_rbconfig(rbconfig_path)@target_rbconfig =Gem::TargetRbConfig.from_path(rbconfig_path)Gem::Platform.local(refresh:true)Gem.platforms<<Gem::Platform.localunlessGem.platforms.include?Gem::Platform.local@target_rbconfigend
Source
# File lib/rubygems.rb, line 1091defself.solaris_platform?RUBY_PLATFORM.include?("solaris")end

Is this platform Solaris?

Source
# File lib/rubygems.rb, line 1232defself.source_date_epochTime.at(source_date_epoch_string.to_i).utc.freezeend

Returns the value ofGem.source_date_epoch_string, as aTime object.

This is used throughout RubyGems for enabling reproducible builds.

Source
# File lib/rubygems.rb, line 1216defself.source_date_epoch_stringspecified_epoch =ENV["SOURCE_DATE_EPOCH"]# If it's empty or just whitespace, treat it like it wasn't set at all.specified_epoch =nilif!specified_epoch.nil?&&specified_epoch.strip.empty?epoch =specified_epoch||DEFAULT_SOURCE_DATE_EPOCH.to_sepoch.stripend

If the SOURCE_DATE_EPOCH environment variable is set, returns it’s value. Otherwise, returnsDEFAULT_SOURCE_DATE_EPOCH as a string.

NOTE(@duckinator): The implementation is a tad weird because we want to:

1. Make builds reproducible by default, by having this function always   return the same result during a given run.2. Allow changing ENV['SOURCE_DATE_EPOCH'] at runtime, since multiple   tests that set this variable will be run in a single process.

If you simplify this function and a lot of tests fail, that is likely due to #2 above.

Details on SOURCE_DATE_EPOCH:reproducible-builds.org/specs/source-date-epoch/

Source
# File lib/rubygems.rb, line 976defself.sourcessource_list =configuration.sources||default_sources@sources||=Gem::SourceList.from(source_list)end

Returns anArray of sources to fetch remote gems from. Usesdefault_sources if the sources list is empty.

Source
# File lib/rubygems.rb, line 988defself.sources=(new_sources)if!new_sources@sources =nilelse@sources =Gem::SourceList.from(new_sources)endend

Need to be able to set the sources without callingGem.sources.replace since that would cause an infinite loop.

DOC: This comment is not documentation about the method itself, it’s more of a code comment about the implementation.

Source
# File lib/rubygems.rb, line 430defself.spec_cache_dirpaths.spec_cache_dirend
Source
# File lib/rubygems/defaults.rb, line 140defself.state_file@state_file||=File.join(Gem.state_home,"gem","last_update_check")end

The path to standard location of the user’s state file.

Source
# File lib/rubygems/defaults.rb, line 161defself.state_home@state_home||=ENV["XDG_STATE_HOME"]||File.join(Gem.user_home,".local","state")end

The path to standard location of the user’s state directory.

Source
# File lib/rubygems.rb, line 999defself.suffix_pattern@suffix_pattern||="{#{suffixes.join(",")}}"end

Glob pattern for require-able path suffixes.

Source
# File lib/rubygems.rb, line 1006defself.suffix_regexp@suffix_regexp||=/#{Regexp.union(suffixes)}\z/end

Regexp for require-able path suffixes.

Source
# File lib/rubygems.rb, line 1027defself.suffixes@suffixes||= ["",".rb",*%w[DLEXT DLEXT2].mapdo|key|val =RbConfig::CONFIG[key]nextunlessval&&!val.empty?".#{val}"end].compact.uniqend

Suffixes for require-able paths.

Source
# File lib/rubygems.rb, line 440defself.target_rbconfig@target_rbconfig||Gem::TargetRbConfig.for_running_rubyend

TheRbConfig object for the deployment target platform.

This is usually the same as the running platform, but may be different if you are cross-compiling.

Source
# File lib/rubygems.rb, line 1048defself.time(msg,width =0,display =Gem.configuration.verbose)now =Time.nowvalue =yieldelapsed =Time.now-nowui.sayformat("%2$*1$s: %3$3.3fs",-width,msg,elapsed)ifdisplayvalueend

Prints the amount of time the supplied block takes to run using the debug UI output.

Source
# File lib/rubygems.rb, line 181defself.try_activate(path)# finds the _latest_ version... regardless of loaded specs and their deps# if another gem had a requirement that would mean we shouldn't# activate the latest version, then either it would already be activated# or if it was ambiguous (and thus unresolved) the code in our custom# require will try to activate the more specific version.spec =Gem::Specification.find_by_pathpathreturnfalseunlessspecreturntrueifspec.activated?beginspec.activaterescueGem::LoadError=>e# this could fail due to gem dep collisions, go laxspec_by_name =Gem::Specification.find_by_name(spec.name)ifspec_by_name.nil?raiseeelsespec_by_name.activateendendtrueend

Try to activate a gem containingpath. Returns true if activation succeeded or wasn’t needed because it was already activated. Returns false if it can’t find the path in a gem.

Source
# File lib/rubygems.rb, line 1063defself.uirequire_relative"rubygems/user_interaction"Gem::DefaultUserInteraction.uiend

Lazily loadsDefaultUserInteraction and returns the default UI.

Source
# File lib/rubygems.rb, line 1157defself.use_gemdeps(path =nil)raise_exception =pathpath||=ENV["RUBYGEMS_GEMDEPS"]returnunlesspathpath =path.dupifpath=="-"Gem::Util.traverse_parentsDir.pwddo|directory|dep_file =GEM_DEP_FILES.find {|f|File.file?(f) }nextunlessdep_filepath =File.joindirectory,dep_filebreakendendunlessFile.file?pathreturnunlessraise_exceptionraiseArgumentError,"Unable to find gem dependencies file at #{path}"endENV["BUNDLE_GEMFILE"]||=File.expand_path(path)require_relative"rubygems/user_interaction"require"bundler"beginGem::DefaultUserInteraction.use_ui(ui)doBundler.ui.silencedo@gemdeps =Bundler.setupendensureGem::DefaultUserInteraction.ui.closeendrescueBundler::BundlerError=>ewarne.messagewarn"You may need to `bundle install` to install missing gems"warn""endend

Looks for a gem dependency file atpath and activates the gems in the file if found. If the file is not found anArgumentError is raised.

Ifpath is not given the RUBYGEMS_GEMDEPS environment variable is used, but if no file is found no exception is raised.

If ‘-’ is given forpath 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 theRUBYGEMS_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.

Source
# File lib/rubygems.rb, line 1073defself.use_paths(home,*paths)paths.flatten!paths.compact!hash = {"GEM_HOME"=>home,"GEM_PATH"=>paths.empty??home:paths.join(File::PATH_SEPARATOR) }hash.delete_if {|_,v|v.nil? }self.paths =hashend

Use thehome andpaths values forGem.dir andGem.path. Used mainly by the unit tests to provide environment isolation.

Source
# File lib/rubygems/defaults.rb, line 103defself.user_dirgem_dir =File.join(Gem.user_home,".gem")gem_dir =File.join(Gem.data_home,"gem")unlessFile.exist?(gem_dir)parts = [gem_dir,ruby_engine]parts<<RbConfig::CONFIG["ruby_version"]unlessRbConfig::CONFIG["ruby_version"].empty?File.joinpartsend

Path for gems in the user’s home directory

Source
# File lib/rubygems/defaults.rb, line 96defself.user_home@user_home||=find_homeend

The home directory for the user.

Source
# File lib/rubygems/win_platform.rb, line 23defself.win_platform?if@@win_platform.nil?ruby_platform =RbConfig::CONFIG["host_os"]@@win_platform =!WIN_PATTERNS.find {|r|ruby_platform=~r }.nil?end@@win_platformend

Is this a windows platform?

Source
# File lib/rubygems.rb, line 838defself.write_binary(path,data)File.binwrite(path,data)rescueErrno::ENOSPC# If we ran out of space but the file exists, it's *guaranteed* to be corrupted.File.delete(path)ifFile.exist?(path)raiseend

Safely write a file in binary mode on all platforms.

Private Class Methods

Source
# File lib/rubygems.rb, line 1368defalready_loaded?(file)$LOADED_FEATURES.any?do|feature_path|feature_path.end_with?(file)&&default_gem_load_paths.any? {|load_path_entry|feature_path=="#{load_path_entry}/#{file}" }endend
Source
# File lib/rubygems.rb, line 1374defdefault_gem_load_paths@default_gem_load_paths||=$LOAD_PATH[load_path_insert_index..-1].mapdo|lp|expanded =File.expand_path(lp)nextexpandedunlessFile.exist?(expanded)File.realpath(expanded)endend
Source
# File lib/rubygems.rb, line 236defself.find_and_activate_spec_for_exe(name,exec_name,requirements)spec =find_spec_for_exename,exec_name,requirementsGem::LOADED_SPECS_MUTEX.synchronizedospec.activatefinish_resolveendspecend
Source
# File lib/rubygems/defaults.rb, line 81defself.find_homeDir.home.duprescueStandardErrorifGem.win_platform?File.expand_pathFile.join(ENV["HOMEDRIVE"]||ENV["SystemDrive"],"/")elseFile.expand_path"/"endend

Finds the user’s home directory.

Source
# File lib/rubygems.rb, line 246defself.find_spec_for_exe(name,exec_name,requirements)raiseArgumentError,"you must supply exec_name"unlessexec_namedep =Gem::Dependency.newname,requirementsloaded =Gem.loaded_specs[name]returnloadedifloaded&&dep.matches_spec?(loaded)specs =dep.matching_specs(true)specs =specs.find_alldo|spec|spec.executables.include?exec_nameendifexec_nameunlessspec =specs.firstmsg ="can't find gem #{dep} with executable #{exec_name}"raiseGem::GemNotFoundException,msgendspecend