RubyGems is the Ruby standard for publishing and managing third party libraries.
For user documentation, see:
-
gem help
andgem help [command]
For gem developer documentation see:
-
Gem::Version
for version dependency notes
Further RubyGems documentation can be found at:
-
RubyGems API (also available from
gem server
)
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 the Graph gem which adds a gem 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. See Gem::pre_install
, Gem::pre_uninstall
, Gem::post_install
, Gem::post_uninstall
.
Bugs
You can submit bugs to the RubyGems bug tracker on GitHub
Credits
RubyGems is currently maintained by Eric Hodel.
RubyGems was originally developed at RubyConf 2003 by:
-
Rich Kilmer – rich(at)infoether.com
-
Chad Fowler – chad(at)chadfowler.com
-
David Black – dblack(at)wobblini.net
-
Paul Brannan – paul(at)atdesk.com
-
Jim Weirich – jim(at)weirichhouse.org
Contributors:
-
Gavin Sinclair – gsinclair(at)soyabean.com.au
-
George Marrows – george.marrows(at)ntlworld.com
-
Dick Davies – rasputnik(at)hellooperator.net
-
Mauricio Fernandez – batsman.geo(at)yahoo.com
-
Simon Strandgaard – neoneye(at)adslhome.dk
-
Dave Glasser – glasser(at)mit.edu
-
Paul Duncan – pabs(at)pablotron.org
-
Ville Aine – vaine(at)cs.helsinki.fi
-
Eric Hodel – drbrain(at)segment7.net
-
Daniel Berger – djberg96(at)gmail.com
-
Phil Hagelberg – technomancy(at)gmail.com
-
Ryan Davis – ryand-ruby(at)zenspider.com
-
Evan Phoenix – evan(at)fallingsnow.net
-
Steve Klabnik – steve(at)steveklabnik.com
(If your name is missing, PLEASE let us know!)
License
See LICENSE.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 be
removed in the next RubyGems version.
Also provides skip_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 of deprecate
and rubygems_deprecate
:
class Legacy
def self.some_class_method
# ...
end
def some_instance_method
# ...
end
def some_old_method
# ...
end
extend Gem::Deprecate
deprecate :some_instance_method, "X.z", 2011, 4
rubygems_deprecate :some_old_method, "Modern#some_new_method"
class << self
extend Gem::Deprecate
deprecate :some_class_method, :none, 2011, 4
end
end
Example usage of rubygems_deprecate_command
:
class Gem::Commands::QueryCommand < Gem::Command
extend Gem::Deprecate
rubygems_deprecate_command
# ...
end
Example usage of skip_during
:
class TestSomething < Gem::Testcase
def test_some_thing_with_deprecations
Gem::Deprecate.skip_during do
actual_stdout, actual_stderr = capture_output do
Gem.something_deprecated
end
assert_empty actual_stdout
assert_equal(expected, actual_stderr)
end
end
end
- MODULE Gem::BUNDLED_GEMS
- MODULE Gem::BundlerVersionFinder
- MODULE Gem::CIDetector
- MODULE Gem::Commands
- MODULE Gem::DefaultUserInteraction
- MODULE Gem::Deprecate
- MODULE Gem::Ext
- MODULE Gem::GemcutterUtilities
- MODULE Gem::GemspecHelpers
- MODULE Gem::InstallUpdateOptions
- MODULE Gem::InstallerUninstallerUtils
- MODULE Gem::LocalRemoteOptions
- MODULE Gem::QueryUtils
- MODULE Gem::SafeMarshal
- MODULE Gem::SafeYAML
- MODULE Gem::Security
- MODULE Gem::SecurityOption
- MODULE Gem::Text
- MODULE Gem::UpdateSuggestion
- MODULE Gem::UserInteraction
- MODULE Gem::Util
- MODULE Gem::VersionOption
- MODULE Gem::YAMLSerializer
- CLASS Gem::AvailableSet
- CLASS Gem::BasicSpecification
- CLASS Gem::Command
- CLASS Gem::CommandLineError
- CLASS Gem::CommandManager
- CLASS Gem::ConfigFile
- CLASS Gem::ConflictError
- CLASS Gem::ConsoleUI
- CLASS Gem::Dependency
- CLASS Gem::DependencyError
- CLASS Gem::DependencyInstaller
- CLASS Gem::DependencyList
- CLASS Gem::DependencyRemovalException
- CLASS Gem::DependencyResolutionError
- CLASS Gem::Doctor
- CLASS Gem::DocumentError
- CLASS Gem::EndOfYAMLException
- CLASS Gem::ErrorReason
- CLASS Gem::Exception
- CLASS Gem::FilePermissionError
- CLASS Gem::FormatException
- CLASS Gem::GemNotFoundException
- CLASS Gem::GemNotInHomeException
- CLASS Gem::GemRunner
- CLASS Gem::ImpossibleDependenciesError
- CLASS Gem::InstallError
- CLASS Gem::Installer
- CLASS Gem::InvalidSpecificationException
- CLASS Gem::Licenses
- CLASS Gem::LoadError
- CLASS Gem::MissingSpecError
- CLASS Gem::MissingSpecVersionError
- CLASS Gem::NameTuple
- CLASS Gem::NoAliasYAMLTree
- CLASS Gem::OperationNotSupportedError
- CLASS Gem::Package
- CLASS Gem::PackageTask
- CLASS Gem::PathSupport
- CLASS Gem::Platform
- CLASS Gem::PlatformMismatch
- CLASS Gem::RemoteError
- CLASS Gem::RemoteFetcher
- CLASS Gem::RemoteInstallationCancelled
- CLASS Gem::RemoteInstallationSkipped
- CLASS Gem::RemoteSourceException
- CLASS Gem::Request
- CLASS Gem::RequestSet
- CLASS Gem::Requirement
- CLASS Gem::Resolver
- CLASS Gem::RubyVersionMismatch
- CLASS Gem::RuntimeRequirementNotMetError
- CLASS Gem::S3URISigner
- CLASS Gem::SilentUI
- CLASS Gem::Source
- CLASS Gem::SourceFetchProblem
- CLASS Gem::SourceList
- CLASS Gem::SpecFetcher
- CLASS Gem::SpecificGemNotFoundException
- CLASS Gem::Specification
- CLASS Gem::SpecificationPolicy
- CLASS Gem::SpecificationRecord
- CLASS Gem::StreamUI
- CLASS Gem::StubSpecification
- CLASS Gem::SystemExitException
- CLASS Gem::UninstallError
- CLASS Gem::Uninstaller
- CLASS Gem::UnknownCommandError
- CLASS Gem::UnknownCommandSpellChecker
- CLASS Gem::UnsatisfiableDependencyError
- CLASS Gem::Uri
- CLASS Gem::UriFormatter
- CLASS Gem::Validator
- CLASS Gem::VerificationError
- CLASS Gem::Version
- CLASS Gem::WebauthnVerificationError
- CLASS RDoc::RubygemsHook
- A
- B
- C
- D
- E
- F
- H
- I
- J
- L
- M
- N
- O
- P
- R
- S
- T
- U
- W
Constants
DEFAULT_HOST | = | "https://rubygems.org" |
GEM_DEP_FILES | = | %w[ gem.deps.rb gems.rb Gemfile Isolate ].freeze |
LOADED_SPECS_MUTEX | = | Thread::Mutex.new |
MARSHAL_SPEC_DIR | = | "quick/Marshal.#{Gem.marshal_version}/".freeze |
Location of |
||
RDoc | = | ::RDoc::RubygemsHook |
This file is automatically required by RubyGems 1.9 and newer. |
||
REPOSITORY_DEFAULT_GEM_SUBDIRECTORIES | = | %w[ gems specifications/default ].freeze |
Subdirectories in a gem repository for default gems |
||
REPOSITORY_SUBDIRECTORIES | = | %w[ build_info cache doc extensions gems plugins specifications ].freeze |
Subdirectories in a gem repository |
||
RUBYGEMS_DIR | = | __dir__ |
VERSION | = | "3.5.11" |
WIN_PATTERNS | = | [ /bccwin/i, /cygwin/i, /djgpp/i, /mingw/i, /mswin/i, /wince/i, ].freeze |
An |
Attributes
[RW] | disable_system_update_message | 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. |
[RW] | discover_gems_on_require | 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`. |
[R] | done_installing_hooks | The list of hooks to be run after |
[R] | gemdeps | GemDependencyAPI object, which is set when .use_gemdeps is called. This contains all the information from the Gemfile. |
[R] | loaded_specs |
|
[R] | post_build_hooks | The list of hooks to be run after |
[R] | post_install_hooks | The list of hooks to be run after |
[R] | post_reset_hooks | The list of hooks to be run after |
[R] | post_uninstall_hooks | The list of hooks to be run after |
[R] | pre_install_hooks | The list of hooks to be run before |
[R] | pre_reset_hooks | The list of hooks to be run before |
[R] | pre_uninstall_hooks | The list of hooks to be run before |
Class Public methods
activated_gem_paths() Link
The number of paths in the +$LOAD_PATH+ from activated gems. Used to prioritize -I
and ENV['RUBYLIB']
entries during require
.
add_to_load_path(*paths) Link
Add a list of paths to the $LOAD_PATH at the proper place.
bin_path(name, exec_name = nil, *requirements) Link
Find
the full path to the executable for gem name
. If the exec_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.
binary_mode() Link
The mode needed to read a file as straight binary.
bindir(install_dir=Gem.dir) Link
The path where gem executables are to be installed.
cache_home() Link
The path to standard location of the user’s cache directory.
clear_default_specs() Link
Clear default gem related variables. It is for test
clear_paths() Link
Reset the dir
and path
values. The next time dir
or path
is requested, the values will be calculated from scratch. This is mainly used by the unit tests to provide test isolation.
config_file() Link
The path to standard location of the user’s .gemrc file.
config_home() Link
The path to standard location of the user’s configuration directory.
configuration() Link
The standard configuration object for gems.
configuration=(config) Link
Use the given configuration object (which implements the ConfigFile
protocol) as the standard configuration object.
data_home() Link
The path to standard location of the user’s data directory.
default_bindir() Link
The default directory for binaries
default_cert_path() Link
The default signing certificate chain path
# File ruby/lib/rubygems/defaults.rb, line 228 def self.default_cert_path default_cert_path = File.join Gem.user_home, ".gem", "gem-public_cert.pem" unless File.exist?(default_cert_path) default_cert_path = File.join Gem.data_home, "gem", "gem-public_cert.pem" end default_cert_path end
default_dir() Link
Default home directory path to be used if an alternate value is not specified in the environment
default_exec_format() Link
Deduce Ruby’s –program-prefix and –program-suffix from its install name
# File ruby/lib/rubygems/defaults.rb, line 186 def self.default_exec_format exec_format = begin RbConfig::CONFIG["ruby_install_name"].sub("ruby", "%s") rescue StandardError "%s" end unless exec_format.include?("%s") raise Gem::Exception, "[BUG] invalid exec_format #{exec_format.inspect}, no %s" end exec_format end
default_ext_dir_for(base_dir) Link
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
default_key_path() Link
The default signing key path
# File ruby/lib/rubygems/defaults.rb, line 215 def self.default_key_path default_key_path = File.join Gem.user_home, ".gem", "gem-private_key.pem" unless File.exist?(default_key_path) default_key_path = File.join Gem.data_home, "gem", "gem-private_key.pem" end default_key_path end
default_path() Link
Default gem load path
default_rubygems_dirs() Link
Paths where RubyGems’ .rb files and bin files are installed
default_spec_cache_dir() Link
Default spec directory path to be used if an alternate value is not specified in the environment
# File ruby/lib/rubygems/defaults.rb, line 23 def self.default_spec_cache_dir default_spec_cache_dir = File.join Gem.user_home, ".gem", "specs" unless File.exist?(default_spec_cache_dir) default_spec_cache_dir = File.join Gem.cache_home, "gem", "specs" end default_spec_cache_dir end
default_specifications_dir() Link
Path to specification files of default gems.
deflate(data) Link
A Zlib::Deflate.deflate
wrapper
dir() Link
The path where gems are to be installed.
done_installing(&hook) Link
Adds a post-installs hook that will be passed a Gem::DependencyInstaller
and a list of installed specifications when Gem::DependencyInstaller#install
is complete
dynamic_library_suffixes() Link
Suffixes for dynamic library require-able paths.
ensure_default_gem_subdirectories(dir = Gem.dir, mode = nil) Link
Quietly ensure the Gem directory dir
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.
If mode
is given, missing directories are created with this mode.
World-writable directories will never be created.
ensure_gem_subdirectories(dir = Gem.dir, mode = nil) Link
Quietly ensure the Gem directory dir
contains all the proper subdirectories. If we can’t create a directory due to a permission problem, then we will silently continue.
If mode
is given, missing directories are created with this mode.
World-writable directories will never be created.
env_requirement(gem_name) Link
find_config_file() Link
Finds the user’s config file
find_default_spec(path) Link
Find
a Gem::Specification
of default gem from path
find_files(glob, check_load_path=true) Link
Returns a list of paths matching glob
that can be used by a gem to pick up features from other gems. For example:
Gem.find_files('rdoc/discover').each do |path| load path end
if check_load_path
is true (the default), then find_files
also searches $LOAD_PATH for files as well as gems.
Note that find_files
will return all files even if they are from different versions of the same gem. See also find_latest_files
# File ruby/lib/rubygems.rb, line 472 def self.find_files(glob, check_load_path=true) files = [] files = find_files_from_load_path glob if check_load_path gem_specifications = @gemdeps ? Gem.loaded_specs.values : Gem::Specification.stubs files.concat gem_specifications.map {|spec| spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}") }.flatten # $LOAD_PATH might contain duplicate entries or reference # the spec dirs directly, so we prune. files.uniq! if check_load_path files end
find_latest_files(glob, check_load_path=true) Link
Returns a list of paths matching glob
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').each do |path| load path end
if check_load_path
is true (the default), then find_latest_files
also searches $LOAD_PATH for files as well as gems.
Unlike find_files
, find_latest_files
will return only files from the latest version of a gem.
# File ruby/lib/rubygems.rb, line 509 def self.find_latest_files(glob, check_load_path=true) files = [] files = find_files_from_load_path glob if check_load_path files.concat Gem::Specification.latest_specs(true).map {|spec| spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}") }.flatten # $LOAD_PATH might contain duplicate entries or reference # the spec dirs directly, so we prune. files.uniq! if check_load_path files end
find_unresolved_default_spec(path) Link
Find
an unresolved Gem::Specification
of default gem from path
finish_resolve(request_set=Gem::RequestSet.new) Link
# File ruby/lib/rubygems.rb, line 220 def self.finish_resolve(request_set=Gem::RequestSet.new) request_set.import Gem::Specification.unresolved_deps.values request_set.import Gem.loaded_specs.values.map {|s| Gem::Dependency.new(s.name, s.version) } request_set.resolve_current.each do |s| s.full_spec.activate end end
freebsd_platform?() Link
Is this platform FreeBSD
host() Link
Get the default RubyGems API host. This is normally https://rubygems.org
.
install(name, version = Gem::Requirement.default, *options) Link
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", ...>]
java_platform?() Link
Is this a java platform?
latest_rubygems_version() Link
Returns the latest release version of RubyGems.
latest_spec_for(name) Link
Returns the latest release-version specification for the gem name
.
latest_version_for(name) Link
Returns the version of the latest release-version of gem name
load_path_insert_index() Link
The index to insert activated gem paths into the $LOAD_PATH. The activated gem’s paths are inserted before site lib directory by default.
load_safe_marshal() Link
load_yaml() Link
location_of_caller(depth = 1) Link
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)
needs() Link
open_file(path, flags, &block) Link
Open a file with given flags, and on Windows protect access with flock
# File ruby/lib/rubygems.rb, line 776 def self.open_file(path, flags, &block) File.open(path, flags) do |io| if !java_platform? && win_platform? begin io.flock(File::LOCK_EX) rescue Errno::ENOSYS, Errno::ENOTSUP end end yield io end rescue Errno::ENOLCK # NFS if Thread.main != Thread.current raise else File.open(path, flags) do |io| yield io end end end
operating_system_defaults() Link
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
path() Link
paths() Link
Retrieve the PathSupport
object that RubyGems uses to lookup files.
paths=(env) Link
Initialize the filesystem paths to use from env
. env
is a hash-like object (typically ENV
) that is queried for ‘GEM_HOME’, ‘GEM_PATH’, and ‘GEM_SPEC_CACHE’ Keys for the env
hash should be Strings, and values of the hash should be Strings or nil
.
# File ruby/lib/rubygems.rb, line 357 def self.paths=(env) clear_paths target = {} env.each_pair do |k,v| case k when "GEM_HOME", "GEM_PATH", "GEM_SPEC_CACHE" case v when nil, String target[k] = v when Array unless Gem::Deprecate.skip warn <<-EOWARN Array 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]} EOWARN end target[k] = v.join File::PATH_SEPARATOR end else target[k] = v end end @paths = Gem::PathSupport.new ENV.to_hash.merge(target) Gem::Specification.dirs = @paths.path end
platform_defaults() Link
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
plugin_suffix_pattern() Link
Glob pattern for require-able plugin suffixes.
plugindir(install_dir=Gem.dir) Link
The path were rubygems plugins are to be installed.
post_build(&hook) Link
Adds a post-build hook that will be passed an Gem::Installer
instance when Gem::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 returns false
then the gem’s files will be removed and the install will be aborted.
post_install(&hook) Link
Adds a post-install hook that will be passed an Gem::Installer
instance when Gem::Installer#install
is called
post_reset(&hook) Link
Adds a hook that will get run after Gem::Specification.reset
is run.
post_uninstall(&hook) Link
Adds a post-uninstall hook that will be passed a Gem::Uninstaller
instance and the spec that was uninstalled when Gem::Uninstaller#uninstall
is called
pre_install(&hook) Link
Adds a pre-install hook that will be passed an Gem::Installer
instance when Gem::Installer#install
is called. If the hook returns false
then the install will be aborted.
pre_reset(&hook) Link
Adds a hook that will get run before Gem::Specification.reset
is run.
pre_uninstall(&hook) Link
Adds a pre-uninstall hook that will be passed an Gem::Uninstaller
instance and the spec that will be uninstalled when Gem::Uninstaller#uninstall
is called
prefix() Link
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.
read_binary(path) Link
Safely read a file in binary mode on all platforms.
refresh() Link
Refresh available gems from disk.
register_default_spec(spec) Link
Register a Gem::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.
# File ruby/lib/rubygems.rb, line 1201 def register_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 } } if new_format prefix_group = extended_require_paths.join("|") prefix_pattern = /^(#{prefix_group})/ end spec.files.each do |file| if new_format file = file.sub(prefix_pattern, "") next unless $~ end spec.activate if already_loaded?(file) @path_to_default_spec_map[file] = spec @path_to_default_spec_map[file.sub(suffix_regexp, "")] = spec end end
ruby() Link
The path to the running Ruby interpreter.
ruby_engine() Link
ruby_version() Link
A Gem::Version
for the currently running Ruby.
# File ruby/lib/rubygems.rb, line 856 def self.ruby_version return @ruby_version if defined? @ruby_version version = RUBY_VERSION.dup if RUBY_PATCHLEVEL == -1 if RUBY_ENGINE == "ruby" desc = RUBY_DESCRIPTION[/\Aruby #{Regexp.quote(RUBY_VERSION)}([^ ]+) /, 1] else desc = RUBY_DESCRIPTION[/\A#{RUBY_ENGINE} #{Regexp.quote(RUBY_ENGINE_VERSION)} \(#{RUBY_VERSION}([^ ]+)\) /, 1] end version << ".#{desc}" if desc end @ruby_version = Gem::Version.new version end
rubygems_version() Link
A Gem::Version
for the currently running RubyGems
solaris_platform?() Link
Is this platform Solaris?
source_date_epoch() Link
Returns the value of Gem.source_date_epoch_string
, as a Time
object.
This is used throughout RubyGems for enabling reproducible builds.
source_date_epoch_string() Link
If the SOURCE_DATE_EPOCH environment variable is set, returns it’s value. Otherwise, returns the time that Gem.source_date_epoch_string
was first called in the same format as SOURCE_DATE_EPOCH.
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/
# File ruby/lib/rubygems.rb, line 1137 def self.source_date_epoch_string # The value used if $SOURCE_DATE_EPOCH is not set. @default_source_date_epoch ||= Time.now.to_i.to_s specified_epoch = ENV["SOURCE_DATE_EPOCH"] # If it's empty or just whitespace, treat it like it wasn't set at all. specified_epoch = nil if !specified_epoch.nil? && specified_epoch.strip.empty? epoch = specified_epoch || @default_source_date_epoch epoch.strip end
sources() Link
Returns an Array
of sources to fetch remote gems from. Uses default_sources
if the sources list is empty.
sources=(new_sources) Link
Need to be able to set the sources without calling Gem.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.
spec_cache_dir() Link
state_file() Link
The path to standard location of the user’s state file.
state_home() Link
The path to standard location of the user’s state directory.
suffix_pattern() Link
Glob pattern for require-able path suffixes.
suffixes() Link
Suffixes for require-able paths.
time(msg, width = 0, display = Gem.configuration.verbose) Link
Prints the amount of time the supplied block takes to run using the debug UI output.
try_activate(path) Link
Try to activate a gem containing path
. 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.
# File ruby/lib/rubygems.rb, line 187 def self.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_path path return false unless spec return true if spec.activated? begin spec.activate rescue Gem::LoadError => e # this could fail due to gem dep collisions, go lax spec_by_name = Gem::Specification.find_by_name(spec.name) if spec_by_name.nil? raise e else spec_by_name.activate end end true end
ui() Link
Lazily loads DefaultUserInteraction
and returns the default UI.
use_gemdeps(path = nil) Link
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 ruby/lib/rubygems.rb, line 1077 def self.use_gemdeps(path = nil) raise_exception = path path ||= ENV["RUBYGEMS_GEMDEPS"] return unless path path = path.dup if path == "-" 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 unless File.file? path return unless raise_exception raise ArgumentError, "Unable to find gem dependencies file at #{path}" end ENV["BUNDLE_GEMFILE"] ||= File.expand_path(path) require_relative "rubygems/user_interaction" require "bundler" begin Gem::DefaultUserInteraction.use_ui(ui) do Bundler.ui.silence do @gemdeps = Bundler.setup end ensure Gem::DefaultUserInteraction.ui.close end rescue Bundler::BundlerError => e warn e.message warn "You may need to `bundle install` to install missing gems" warn "" end end
use_paths(home, *paths) Link
user_dir() Link
Path for gems in the user’s home directory
# File ruby/lib/rubygems/defaults.rb, line 103 def self.user_dir gem_dir = File.join(Gem.user_home, ".gem") gem_dir = File.join(Gem.data_home, "gem") unless File.exist?(gem_dir) parts = [gem_dir, ruby_engine] parts << RbConfig::CONFIG["ruby_version"] unless RbConfig::CONFIG["ruby_version"].empty? File.join parts end
user_home() Link
The home directory for the user.
win_platform?() Link
Is this a windows platform?
write_binary(path, data) Link
Safely write a file in binary mode on all platforms.