Namespace

Class Index [+]

Quicksearch

Gem

Provides a single method deprecate to be used to declare when something is going away.

    class Legacy
      def self.klass_method
        # ...
      end

      def instance_method
        # ...
      end

      extend Gem::Deprecate
      deprecate :instance_method, "X.z", 2011, 4

      class << self
        extend Gem::Deprecate
        deprecate :klass_method, :none, 2011, 4
      end
    end


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

As of RubyGems 1.3.2, RubyGems will load plugins installed in gems or $LOAD_PATH. Plugins must be named ‘rubygems_plugin’ (.rb, .so, etc) and placed at the root of your gem’s #. Plugins are discovered via Gem::find_files then loaded. Take care when implementing a plugin as your plugin file may be loaded multiple times if multiple versions of your gem are installed.

For an example plugin, see the graph gem which adds a `gem graph` command.

RubyGems Defaults, Packaging

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

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

For Ruby implementers, provide lib/rubygems/#{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 and 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 RubyForge

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!)

Thanks!

-The RubyGems Team

Constants

QUICKLOADER_SUCKAGE
GEM_PRELUDE_SUCKAGE
VERSION
WIN_PATTERNS

An Array of Regexps that match windows ruby platforms.

MARSHAL_SPEC_DIR

Location of Marshal quick gemspecs on remote repositories

Attributes

ssl_available[W]

Is SSL available?

loaded_specs[R]

Hash of loaded Gem::Specification keyed by name

post_build_hooks[R]

The list of hooks to be run before Gem::Install#install finishes installation

post_install_hooks[R]

The list of hooks to be run before Gem::Install#install does any work

post_reset_hooks[R]

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

post_uninstall_hooks[R]

The list of hooks to be run before Gem::Uninstall#uninstall does any work

pre_install_hooks[R]

The list of hooks to be run after Gem::Install#install is finished

pre_reset_hooks[R]

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

pre_uninstall_hooks[R]

The list of hooks to be run after Gem::Uninstall#uninstall is finished

Public Class Methods

activate(dep, *requirements) click to toggle source

Activates an installed gem matching dep. The gem must satisfy requirements.

Returns true if the gem is activated, false if it is already loaded, or an exception otherwise.

Gem#activate adds the library paths in dep to $LOAD_PATH. Before a Gem is activated its required Gems are activated. If the version information is omitted, the highest version Gem of the supplied name is loaded. If a Gem is not found that meets the version requirements or a required Gem is not found, a Gem::LoadError is raised.

More information on version requirements can be found in the Gem::Requirement and Gem::Version documentation.

     # File lib/rubygems.rb, line 231
231:   def self.activate(dep, *requirements)
232:     raise ArgumentError, "Deprecated use of Gem.activate(dep)" if
233:       Gem::Dependency === dep
234: 
235:     Gem::Specification.find_by_name(dep, *requirements).activate
236:   end
all_load_paths() click to toggle source

An Array of all possible load paths for all versions of all gems in the Gem installation.

     # File lib/rubygems.rb, line 254
254:   def self.all_load_paths
255:     result = []
256: 
257:     Gem.path.each do |gemdir|
258:       each_load_path all_partials(gemdir) do |load_path|
259:         result << gemdir.add(load_path).expand_path
260:       end
261:     end
262: 
263:     result
264:   end
available?(dep, *requirements) click to toggle source

See if a given gem is available.

     # File lib/rubygems.rb, line 278
278:   def self.available?(dep, *requirements)
279:     requirements = Gem::Requirement.default if requirements.empty?
280: 
281:     unless dep.respond_to?(:name) and dep.respond_to?(:requirement) then
282:       dep = Gem::Dependency.new dep, requirements
283:     end
284: 
285:     not dep.matching_specs(true).empty?
286:   end
bin_path(name, exec_name = nil, *requirements) click to toggle source

Find the full path to the executable for gem name. If the exec_name is not given, the gem’s default_executable is chosen, otherwise the specified executable’s path is returned. requirements allows you to specify specific gem versions.

     # File lib/rubygems.rb, line 294
294:   def self.bin_path(name, exec_name = nil, *requirements)
295:     # TODO: fails test_self_bin_path_bin_file_gone_in_latest
296:     # Gem::Specification.find_by_name(name, *requirements).bin_file exec_name
297: 
298:     raise ArgumentError, "you must supply exec_name" unless exec_name
299: 
300:     requirements = Gem::Requirement.default if
301:       requirements.empty?
302: 
303:     specs = Gem::Dependency.new(name, requirements).matching_specs(true)
304: 
305:     raise Gem::GemNotFoundException,
306:           "can't find gem #{name} (#{requirements})" if specs.empty?
307: 
308:     specs = specs.find_all { |spec|
309:       spec.executables.include? exec_name
310:     } if exec_name
311: 
312:     unless spec = specs.last
313:       msg = "can't find gem #{name} (#{requirements}) with executable #{exec_name}"
314:       raise Gem::GemNotFoundException, msg
315:     end
316: 
317:     spec.bin_file exec_name
318:   end
binary_mode() click to toggle source

The mode needed to read a file as straight binary.

     # File lib/rubygems.rb, line 323
323:   def self.binary_mode
324:     'rb'
325:   end
bindir(install_dir=Gem.dir) click to toggle source

The path where gem executables are to be installed.

     # File lib/rubygems.rb, line 330
330:   def self.bindir(install_dir=Gem.dir)
331:     # TODO: move to Gem::Dirs
332:     return File.join install_dir, 'bin' unless
333:       install_dir.to_s == Gem.default_dir.to_s
334:     Gem.default_bindir
335:   end
cache_dir(custom_dir=false) click to toggle source

Get the appropriate cache path.

Pass a string to use a different base path, or nil/false (default) for Gem.dir.

     # File lib/rubygems.rb, line 692
692:   def self.cache_dir(custom_dir=false)
693:     File.join(custom_dir || Gem.dir, "cache")
694:   end
cache_gem(filename, user_dir=false) click to toggle source

Given a gem path, find the gem in cache.

Pass a string as the second argument to use a different base path, or nil/false (default) for Gem.dir.

     # File lib/rubygems.rb, line 702
702:   def self.cache_gem(filename, user_dir=false)
703:     cache_dir(user_dir).add(filename)
704:   end
clear_paths() click to toggle source

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.

     # File lib/rubygems.rb, line 342
342:   def self.clear_paths
343:     @@source_index = nil
344:     @paths         = nil
345:     @user_home     = nil
346:     @searcher      = nil
347:     Gem::Specification.reset
348:   end
config_file() click to toggle source

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

     # File lib/rubygems.rb, line 353
353:   def self.config_file
354:     @config_file ||= File.join Gem.user_home, '.gemrc'
355:   end
configuration() click to toggle source

The standard configuration object for gems.

     # File lib/rubygems.rb, line 360
360:   def self.configuration
361:     @configuration ||= Gem::ConfigFile.new []
362:   end
configuration=(config) click to toggle source

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

     # File lib/rubygems.rb, line 368
368:   def self.configuration=(config)
369:     @configuration = config
370:   end
datadir(gem_name) click to toggle source

The path the the data directory specified by the gem name. If the package is not available as a gem, return nil.

     # File lib/rubygems.rb, line 376
376:   def self.datadir(gem_name)
377: # TODO: deprecate
378:     spec = @loaded_specs[gem_name]
379:     return nil if spec.nil?
380:     File.join spec.full_gem_path, "data", gem_name
381:   end
default_bindir() click to toggle source

The default directory for binaries

    # File lib/rubygems/defaults.rb, line 81
81:   def self.default_bindir
82:     if defined? RUBY_FRAMEWORK_VERSION then # mac framework support
83:       '/usr/bin'
84:     else # generic install
85:       ConfigMap[:bindir]
86:     end
87:   end
default_dir() click to toggle source

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

    # File lib/rubygems/defaults.rb, line 21
21:   def self.default_dir
22:     path = if defined? RUBY_FRAMEWORK_VERSION then
23:              [
24:                File.dirname(ConfigMap[:sitedir]),
25:                'Gems',
26:                ConfigMap[:ruby_version]
27:              ]
28:            elsif ConfigMap[:rubylibprefix] then
29:              [
30:               ConfigMap[:rubylibprefix],
31:               'gems',
32:               ConfigMap[:ruby_version]
33:              ]
34:            else
35:              [
36:                ConfigMap[:libdir],
37:                ruby_engine,
38:                'gems',
39:                ConfigMap[:ruby_version]
40:              ]
41:            end
42: 
43:     @default_dir ||= File.join(*path)
44:   end
default_exec_format() click to toggle source

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

    # File lib/rubygems/defaults.rb, line 67
67:   def self.default_exec_format
68:     exec_format = ConfigMap[:ruby_install_name].sub('ruby', '%s') rescue '%s'
69: 
70:     unless exec_format =~ /%s/ then
71:       raise Gem::Exception,
72:         "[BUG] invalid exec_format #{exec_format.inspect}, no %s"
73:     end
74: 
75:     exec_format
76:   end
default_path() click to toggle source

Default gem load path

    # File lib/rubygems/defaults.rb, line 56
56:   def self.default_path
57:     if File.exist? Gem.user_home then
58:       [user_dir, default_dir]
59:     else
60:       [default_dir]
61:     end
62:   end
default_sources() click to toggle source

An Array of the default sources that come with RubyGems

    # File lib/rubygems/defaults.rb, line 13
13:   def self.default_sources
14:     ]http://rubygems.org/]
15:   end
default_system_source_cache_dir() click to toggle source

The default system-wide source info cache directory

    # File lib/rubygems/defaults.rb, line 92
92:   def self.default_system_source_cache_dir
93:     File.join(Gem.dir, 'source_cache')
94:   end
default_user_source_cache_dir() click to toggle source

The default user-specific source info cache directory

     # File lib/rubygems/defaults.rb, line 99
 99:   def self.default_user_source_cache_dir
100:     #
101:     # NOTE Probably an argument for moving this to per-ruby supported dirs like
102:     # user_dir
103:     #
104:     File.join(Gem.user_home, '.gem', 'source_cache')
105:   end
deflate(data) click to toggle source

A Zlib::Deflate.deflate wrapper

     # File lib/rubygems.rb, line 386
386:   def self.deflate(data)
387:     require 'zlib'
388:     Zlib::Deflate.deflate data
389:   end
dir() click to toggle source

The path where gems are to be installed.

     # File lib/rubygems.rb, line 406
406:   def self.dir
407:     # TODO: raise "no"
408:     paths.home
409:   end
ensure_gem_subdirectories(dir = Gem.dir) click to toggle source

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

     # File lib/rubygems.rb, line 444
444:   def self.ensure_gem_subdirectories dir = Gem.dir
445:     require 'fileutils'
446: 
447:     old_umask = File.umask
448:     File.umask old_umask | 022
449: 
450:     ]cache doc gems specifications].each do |name|
451:       subdir = File.join dir, name
452:       next if File.exist? subdir
453:       FileUtils.mkdir_p subdir rescue nil # in case of perms issues -- lame
454:     end
455:   ensure
456:     File.umask old_umask
457:   end
ensure_ssl_available() click to toggle source

Ensure that SSL is available. Throw an exception if it is not.

    # File lib/rubygems/gem_openssl.rb, line 31
31:     def ensure_ssl_available
32:       unless ssl_available?
33:         raise Gem::Exception, "SSL is not installed on this system"
34:       end
35:     end
find_files(glob, check_load_path=true) click to toggle source

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.

     # File lib/rubygems.rb, line 471
471:   def self.find_files(glob, check_load_path=true)
472:     files = []
473: 
474:     if check_load_path
475:       files = $LOAD_PATH.map { |load_path|
476:         Dir["#{File.expand_path glob, load_path}#{Gem.suffix_pattern}"]
477:       }.flatten.select { |file| File.file? file.untaint }
478:     end
479: 
480:     files.concat Gem::Specification.map { |spec|
481:       spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}")
482:     }.flatten
483: 
484:     # $LOAD_PATH might contain duplicate entries or reference
485:     # the spec dirs directly, so we prune.
486:     files.uniq! if check_load_path
487: 
488:     return files
489:   end
gunzip(data) click to toggle source

Zlib::GzipReader wrapper that unzips data.

     # File lib/rubygems.rb, line 534
534:   def self.gunzip(data)
535:     # TODO: move to utils
536:     require 'stringio'
537:     require 'zlib'
538:     data = StringIO.new data
539: 
540:     Zlib::GzipReader.new(data).read
541:   end
gzip(data) click to toggle source

Zlib::GzipWriter wrapper that zips data.

     # File lib/rubygems.rb, line 546
546:   def self.gzip(data)
547:     # TODO: move to utils
548:     require 'stringio'
549:     require 'zlib'
550:     zipped = StringIO.new
551: 
552:     Zlib::GzipWriter.wrap zipped do |io| io.write data end
553: 
554:     zipped.string
555:   end
host() click to toggle source

Get the default RubyGems API host. This is normally rubygems.org.

     # File lib/rubygems.rb, line 570
570:   def self.host
571:     # TODO: move to utils
572:     @host ||= "https://rubygems.org"
573:   end
host=(host) click to toggle source

Set the default RubyGems API host.

     # File lib/rubygems.rb, line 577
577:   def self.host= host
578:     # TODO: move to utils
579:     @host = host
580:   end
inflate(data) click to toggle source

A Zlib::Inflate#inflate wrapper

     # File lib/rubygems.rb, line 560
560:   def self.inflate(data)
561:     # TODO: move to utils
562:     require 'zlib'
563:     Zlib::Inflate.inflate data
564:   end
latest_load_paths() click to toggle source

Return a list of all possible load paths for the latest version for all gems in the Gem installation.

     # File lib/rubygems.rb, line 586
586:   def self.latest_load_paths
587:     result = []
588: 
589:     Gem.path.each do |gemdir|
590:       each_load_path(latest_partials(gemdir)) do |load_path|
591:         result << load_path
592:       end
593:     end
594: 
595:     result
596:   end
latest_rubygems_version() click to toggle source
     # File lib/rubygems.rb, line 921
921:   def self.latest_rubygems_version
922:     latest_version_for "rubygems-update"
923:   end
latest_spec_for(name) click to toggle source
     # File lib/rubygems.rb, line 902
902:   def self.latest_spec_for name
903:     dependency  = Gem::Dependency.new name
904:     fetcher     = Gem::SpecFetcher.fetcher
905:     spec_tuples = fetcher.find_matching dependency
906: 
907:     match = spec_tuples.select { |(n, _, p), _|
908:       n == name and Gem::Platform.match p
909:     }.sort_by { |(_, version, _), _|
910:       version
911:     }.last
912: 
913:     match and fetcher.fetch_spec(*match)
914:   end
latest_version_for(name) click to toggle source
     # File lib/rubygems.rb, line 916
916:   def self.latest_version_for name
917:     spec = latest_spec_for name
918:     spec and spec.version
919:   end
load_env_plugins() click to toggle source

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

      # File lib/rubygems.rb, line 1086
1086:   def self.load_env_plugins
1087:     path = "rubygems_plugin"
1088: 
1089:     files = []
1090:     $LOAD_PATH.each do |load_path|
1091:       globbed = Dir["#{File.expand_path path, load_path}#{Gem.suffix_pattern}"]
1092: 
1093:       globbed.each do |load_path_file|
1094:         files << load_path_file if File.file?(load_path_file.untaint)
1095:       end
1096:     end
1097: 
1098:     load_plugin_files files
1099:   end
load_path_insert_index() click to toggle source

The index to insert activated gem paths into the $LOAD_PATH.

Defaults to the site lib directory unless gem_prelude.rb has loaded paths, then it inserts the activated gem’s paths before the gem_prelude.rb paths so you can override the gem_prelude.rb default $LOAD_PATH paths.

     # File lib/rubygems.rb, line 626
626:   def self.load_path_insert_index
627:     index = $LOAD_PATH.index ConfigMap[:sitelibdir]
628: 
629:     if QUICKLOADER_SUCKAGE then
630:       $LOAD_PATH.each_with_index do |path, i|
631:         if path.instance_variables.include?(:@gem_prelude_index) or
632:             path.instance_variables.include?('@gem_prelude_index') then
633:           index = i
634:           break
635:         end
636:       end
637:     end
638: 
639:     index
640:   end
load_plugin_files(plugins) click to toggle source

Load plugins as ruby files

      # File lib/rubygems.rb, line 1059
1059:   def self.load_plugin_files(plugins)
1060:     plugins.each do |plugin|
1061: 
1062:       # Skip older versions of the GemCutter plugin: Its commands are in
1063:       # RubyGems proper now.
1064: 
1065:       next if plugin =~ /gemcutter-0\.[0-3]/
1066: 
1067:       begin
1068:         load plugin
1069:       rescue ::Exception => e
1070:         details = "#{plugin.inspect}: #{e.message} (#{e.class})"
1071:         warn "Error loading RubyGems plugin #{details}"
1072:       end
1073:     end
1074:   end
load_plugins() click to toggle source

Find all ‘rubygems_plugin’ files in installed gems and load them

      # File lib/rubygems.rb, line 1079
1079:   def self.load_plugins
1080:     load_plugin_files find_files('rubygems_plugin', false)
1081:   end
load_yaml() click to toggle source

Loads YAML, preferring Psych

     # File lib/rubygems.rb, line 645
645:   def self.load_yaml
646:     begin
647:       gem 'psych', '~> 1.2', '>= 1.2.1' unless ENV['TEST_SYCK']
648:     rescue Gem::LoadError
649:       # It's OK if the user does not have the psych gem installed.  We will
650:       # attempt to require the stdlib version
651:     end
652: 
653:     begin
654:       # Try requiring the gem version *or* stdlib version of psych.
655:       require 'psych' unless ENV['TEST_SYCK']
656:     rescue ::LoadError
657:     ensure
658:       require 'yaml'
659:     end
660: 
661:     # Now that we're sure some kind of yaml library is loaded, pull
662:     # in our hack to deal with Syck's DefaultKey ugliness.
663:     require 'rubygems/syck_hack'
664:   end
loaded_path?(path) click to toggle source
     # File lib/rubygems.rb, line 981
981:   def self.loaded_path? path
982:     # TODO: ruby needs a feature to let us query what's loaded in 1.8 and 1.9
983:     $LOADED_FEATURES.find { |s|
984:       s =~ /(^|\/)#{Regexp.escape path}#{Regexp.union(*Gem.suffixes)}$/
985:     }
986:   end
location_of_caller() click to toggle source

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

     # File lib/rubygems.rb, line 669
669:   def self.location_of_caller
670:     caller[1] =~ /(.*?):(\d+).*?$/
671:     file = $1
672:     lineno = $2.to_i
673: 
674:     # TODO: it is ALWAYS joined! STUPID!
675:     [file, lineno]
676:   end
marshal_version() click to toggle source

The version of the Marshal format for your Ruby.

     # File lib/rubygems.rb, line 681
681:   def self.marshal_version
682:     "#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}"
683:   end
path() click to toggle source
     # File lib/rubygems.rb, line 411
411:   def self.path
412:     # TODO: raise "no"
413:     paths.path
414:   end
paths() click to toggle source
     # File lib/rubygems.rb, line 391
391:   def self.paths
392:     @paths ||= Gem::PathSupport.new
393:   end
paths=(env) click to toggle source
     # File lib/rubygems.rb, line 395
395:   def self.paths=(env)
396:     clear_paths
397:     @paths = Gem::PathSupport.new env
398:     Gem::Specification.dirs = @paths.path # FIX: home is at end
399:   end
platforms() click to toggle source

Array of platforms this RubyGems supports.

     # File lib/rubygems.rb, line 716
716:   def self.platforms
717:     @platforms ||= []
718:     if @platforms.empty?
719:       @platforms = [Gem::Platform::RUBY, Gem::Platform.local]
720:     end
721:     @platforms
722:   end
platforms=(platforms) click to toggle source

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

     # File lib/rubygems.rb, line 709
709:   def self.platforms=(platforms)
710:     @platforms = platforms
711:   end
post_build(&hook) click to toggle source

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.

     # File lib/rubygems.rb, line 731
731:   def self.post_build(&hook)
732:     @post_build_hooks << hook
733:   end
post_install(&hook) click to toggle source

Adds a post-install hook that will be passed an Gem::Installer instance when Gem::Installer#install is called

     # File lib/rubygems.rb, line 739
739:   def self.post_install(&hook)
740:     @post_install_hooks << hook
741:   end
post_reset(&hook) click to toggle source

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

     # File lib/rubygems.rb, line 747
747:   def self.post_reset(&hook)
748:     @post_reset_hooks << hook
749:   end
post_uninstall(&hook) click to toggle source

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

     # File lib/rubygems.rb, line 756
756:   def self.post_uninstall(&hook)
757:     @post_uninstall_hooks << hook
758:   end
pre_install(&hook) click to toggle source

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.

     # File lib/rubygems.rb, line 765
765:   def self.pre_install(&hook)
766:     @pre_install_hooks << hook
767:   end
pre_reset(&hook) click to toggle source

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

     # File lib/rubygems.rb, line 773
773:   def self.pre_reset(&hook)
774:     @pre_reset_hooks << hook
775:   end
pre_uninstall(&hook) click to toggle source

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

     # File lib/rubygems.rb, line 782
782:   def self.pre_uninstall(&hook)
783:     @pre_uninstall_hooks << hook
784:   end
prefix() click to toggle source

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.

     # File lib/rubygems.rb, line 791
791:   def self.prefix
792:     prefix = File.dirname RUBYGEMS_DIR
793: 
794:     if prefix != File.expand_path(ConfigMap[:sitelibdir]) and
795:        prefix != File.expand_path(ConfigMap[:libdir]) and
796:        'lib' == File.basename(RUBYGEMS_DIR) then
797:       prefix
798:     end
799:   end
promote_load_path(gem_name, over_name) click to toggle source

Promotes the load paths of the gem_name over the load paths of over_name. Useful for allowing one gem to override features in another using #.

     # File lib/rubygems.rb, line 806
806:   def self.promote_load_path(gem_name, over_name)
807:     gem = Gem.loaded_specs[gem_name]
808:     over = Gem.loaded_specs[over_name]
809: 
810:     raise ArgumentError, "gem #{gem_name} is not activated" if gem.nil?
811:     raise ArgumentError, "gem #{over_name} is not activated" if over.nil?
812: 
813:     last_gem_path = Gem::Path.path(gem.full_gem_path).add(gem.require_paths.last)
814: 
815:     over_paths = over.require_paths.map do |path|
816:       Gem::Path.path(over.full_gem_path).add(path).to_s
817:     end
818: 
819:     over_paths.each do |path|
820:       $LOAD_PATH.delete path
821:     end
822: 
823:     gem = $LOAD_PATH.index(last_gem_path) + 1
824: 
825:     $LOAD_PATH.insert(gem, *over_paths)
826:   end
read_binary(path) click to toggle source

Safely read a file in binary mode on all platforms.

     # File lib/rubygems.rb, line 840
840:   def self.read_binary(path)
841:     File.open path, binary_mode do |f| f.read end
842:   end
refresh() click to toggle source

Refresh source_index from disk and clear searcher.

     # File lib/rubygems.rb, line 831
831:   def self.refresh
832:     Gem::Specification.reset
833:     @source_index = nil
834:     @searcher = nil
835:   end
required_location(gemname, libfile, *requirements) click to toggle source

Full path to libfile in gemname. Searches for the latest gem unless requirements is given.

     # File lib/rubygems.rb, line 872
872:   def self.required_location(gemname, libfile, *requirements)
873:     requirements = Gem::Requirement.default if requirements.empty?
874: 
875:     matches = Gem::Specification.find_all_by_name gemname, *requirements
876: 
877:     return nil if matches.empty?
878: 
879:     spec = matches.last
880:     spec.require_paths.each do |path|
881:       result = Gem::Path.path(spec.full_gem_path).add(path, libfile)
882:       return result if result.exist?
883:     end
884: 
885:     nil
886:   end
ruby() click to toggle source

The path to the running Ruby interpreter.

     # File lib/rubygems.rb, line 891
891:   def self.ruby
892:     if @ruby.nil? then
893:       @ruby = File.join(ConfigMap[:bindir],
894:                         "#{ConfigMap[:ruby_install_name]}#{ConfigMap[:EXEEXT]}")
895: 
896:       @ruby = "\"#{@ruby}\"" if @ruby =~ /\s/
897:     end
898: 
899:     @ruby
900:   end
ruby=(ruby) click to toggle source

Allows setting path to ruby. This method is available when requiring ‘rubygems/test_case‘

    # File lib/rubygems/test_case.rb, line 60
60:   def self.ruby= ruby
61:     @ruby = ruby
62:   end
ruby_engine() click to toggle source

A wrapper around RUBY_ENGINE const that may not be defined

     # File lib/rubygems/defaults.rb, line 110
110:   def self.ruby_engine
111:     if defined? RUBY_ENGINE then
112:       RUBY_ENGINE
113:     else
114:       'ruby'
115:     end
116:   end
ruby_version() click to toggle source

A Gem::Version for the currently running ruby.

     # File lib/rubygems.rb, line 928
928:   def self.ruby_version
929:     return @ruby_version if defined? @ruby_version
930:     version = RUBY_VERSION.dup
931: 
932:     if defined?(RUBY_PATCHLEVEL) && RUBY_PATCHLEVEL != 1 then
933:       version << ".#{RUBY_PATCHLEVEL}"
934:     elsif defined?(RUBY_REVISION) then
935:       version << ".dev.#{RUBY_REVISION}"
936:     end
937: 
938:     @ruby_version = Gem::Version.new version
939:   end
searcher() click to toggle source

The GemPathSearcher object used to search for matching installed gems.

     # File lib/rubygems.rb, line 944
944:   def self.searcher
945:     @searcher ||= Gem::GemPathSearcher.new
946:   end
searcher=(searcher) click to toggle source

Allows setting the gem path searcher. This method is available when requiring ‘rubygems/test_case‘

    # File lib/rubygems/test_case.rb, line 34
34:   def self.searcher=(searcher)
35:     @searcher = searcher
36:   end
source_index() click to toggle source

Returns the Gem::SourceIndex of specifications that are in the Gem.path

     # File lib/rubygems.rb, line 951
951:   def self.source_index
952:     @@source_index ||= Gem::Deprecate.skip_during do
953:       SourceIndex.new Gem::Specification.dirs
954:     end
955:   end
source_index=(si) click to toggle source

Allows setting the default SourceIndex. This method is available when requiring ‘rubygems/test_case‘

    # File lib/rubygems/test_case.rb, line 42
42:   def self.source_index=(si)
43:     raise "This method is not supported"
44:     Gem::Specification.reset if si # HACK
45:     @@source_index = si
46:   end
sources() click to toggle source

Returns an Array of sources to fetch remote gems from. If the sources list is empty, attempts to load the “sources” gem, then uses default_sources if it is not installed.

     # File lib/rubygems.rb, line 962
962:   def self.sources
963:     @sources ||= default_sources
964:   end
sources=(new_sources) click to toggle source

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

     # File lib/rubygems.rb, line 970
970:   def self.sources= new_sources
971:     @sources = new_sources
972:   end
ssl_available?() click to toggle source

Is SSL (used by the signing commands) available on this platform?

    # File lib/rubygems/gem_openssl.rb, line 19
19:     def ssl_available?
20:       @ssl_available
21:     end
suffix_pattern() click to toggle source

Glob pattern for require-able path suffixes.

     # File lib/rubygems.rb, line 977
977:   def self.suffix_pattern
978:     @suffix_pattern ||= "{#{suffixes.join(',')}}"
979:   end
suffixes() click to toggle source

Suffixes for require-able paths.

      # File lib/rubygems.rb, line 991
 991:   def self.suffixes
 992:     @suffixes ||= ['',
 993:                    '.rb',
 994:                    *%(DLEXT DLEXT2).map { |key|
 995:                      val = RbConfig::CONFIG[key]
 996:                      next unless val and not val.empty?
 997:                      ".#{val}"
 998:                    }
 999:                   ].compact.uniq
1000:   end
time(msg, width = 0, display = Gem.configuration.verbose) click to toggle source

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

      # File lib/rubygems.rb, line 1006
1006:   def self.time(msg, width = 0, display = Gem.configuration.verbose)
1007:     now = Time.now
1008: 
1009:     value = yield
1010: 
1011:     elapsed = Time.now - now
1012: 
1013:     ui.say "%2$*1$s: %3$3.3fs" % [-width, msg, elapsed] if display
1014: 
1015:     value
1016:   end
try_activate(path) click to toggle source

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 lib/rubygems.rb, line 197
197:   def self.try_activate path
198:     # TODO: deprecate when 1.9.3 comes out.
199:     # finds the _latest_ version... regardless of loaded specs and their deps
200: 
201:     # TODO: use find_all and bork if ambiguous
202: 
203:     spec = Gem::Specification.find_by_path path
204:     return false unless spec
205: 
206:     begin
207:       spec.activate
208:     rescue Gem::LoadError # this could fail due to gem dep collisions, go lax
209:       Gem::Specification.find_by_name(spec.name).activate
210:     end
211: 
212:     return true
213:   end
ui() click to toggle source

Lazily loads DefaultUserInteraction and returns the default UI.

      # File lib/rubygems.rb, line 1021
1021:   def self.ui
1022:     require 'rubygems/user_interaction'
1023: 
1024:     Gem::DefaultUserInteraction.ui
1025:   end
unresolved_deps() click to toggle source
     # File lib/rubygems.rb, line 246
246:   def self.unresolved_deps
247:     @unresolved_deps ||= Hash.new { |h, n| h[n] = Gem::Dependency.new n }
248:   end
use_paths(home, *paths) click to toggle source

Use the home and paths values for Gem.dir and Gem.path. Used mainly by the unit tests to provide environment isolation.

      # File lib/rubygems.rb, line 1031
1031:   def self.use_paths(home, *paths)
1032:     paths = nil if paths == [nil]
1033:     paths = paths.first if Array === Array(paths).first
1034:     self.paths = { "GEM_HOME" => home, "GEM_PATH" => paths }
1035:     # TODO: self.paths = home, paths
1036:   end
user_dir() click to toggle source

Path for gems in the user’s home directory

    # File lib/rubygems/defaults.rb, line 49
49:   def self.user_dir
50:     File.join Gem.user_home, '.gem', ruby_engine, ConfigMap[:ruby_version]
51:   end
user_home() click to toggle source

The home directory for the user.

      # File lib/rubygems.rb, line 1041
1041:   def self.user_home
1042:     @user_home ||= find_home
1043:   end
win_platform=(val) click to toggle source

Allows toggling Windows behavior. This method is available when requiring ‘rubygems/test_case‘

    # File lib/rubygems/test_case.rb, line 52
52:   def self.win_platform=(val)
53:     @@win_platform = val
54:   end
win_platform?() click to toggle source

Is this a windows platform?

      # File lib/rubygems.rb, line 1048
1048:   def self.win_platform?
1049:     if @@win_platform.nil? then
1050:       @@win_platform = !!WIN_PATTERNS.find { |r| RUBY_PLATFORM =~ r }
1051:     end
1052: 
1053:     @@win_platform
1054:   end

Private Class Methods

all_partials(gemdir) click to toggle source

Return all the partial paths in gemdir.

     # File lib/rubygems.rb, line 269
269:   def self.all_partials(gemdir)
270:     Dir[File.join(gemdir, "gems/*")]
271:   end
each_load_path(partials) click to toggle source

Expand each partial gem path with each of the required paths specified in the Gem spec. Each expanded path is yielded.

     # File lib/rubygems.rb, line 420
420:   def self.each_load_path(partials)
421:     partials.each do |gp|
422:       base = File.basename gp
423:       specfn = File.join(dir, "specifications", "#{base}.gemspec")
424:       if File.exists? specfn
425:         spec = eval(File.read(specfn))
426:         spec.require_paths.each do |rp|
427:           yield File.join(gp,rp)
428:         end
429:       else
430:         filename = File.join(gp, 'lib')
431:         yield(filename) if File.exists? filename
432:       end
433:     end
434:   end
find_home() click to toggle source

Finds the user’s home directory.

     # File lib/rubygems.rb, line 508
508:   def self.find_home
509:     windows = File::ALT_SEPARATOR
510:     if not windows or RUBY_VERSION >= '1.9' then
511:       File.expand_path "~"
512:     else
513:       ['HOME', 'USERPROFILE'].each do |key|
514:         return File.expand_path ENV[key] if ENV[key]
515:       end
516: 
517:       if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] then
518:         File.expand_path "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}"
519:       end
520:     end
521:   rescue
522:     if windows then
523:       File.expand_path File.join(ENV['HOMEDRIVE'] || ENV['SystemDrive'], '/')
524:     else
525:       File.expand_path "/"
526:     end
527:   end
latest_partials(gemdir) click to toggle source

Return only the latest partial paths in the given gemdir.

     # File lib/rubygems.rb, line 601
601:   def self.latest_partials(gemdir)
602:     latest = {}
603:     all_partials(gemdir).each do |gp|
604:       base = File.basename gp
605: 
606:       if base.to_s =~ /(.*)-((\d+\.)*\d+)/ then
607:         name, version = $1, $2
608:         ver = Gem::Version.new(version)
609:         if latest[name].nil? || ver > latest[name][0]
610:           latest[name] = [ver, gp]
611:         end
612:       end
613:     end
614:     latest.collect { |k,v| v[1] }
615:   end
report_activate_error(gem) click to toggle source

Report a load error during activation. The message of load error depends on whether it was a version mismatch or if there are not gems of any version by the requested name.

     # File lib/rubygems.rb, line 849
849:   def self.report_activate_error(gem)
850:     matches = Gem::Specification.find_by_name(gem.name)
851: 
852:     if matches.empty? then
853:       error = Gem::LoadError.new(
854:           "Could not find RubyGem #{gem.name} (#{gem.requirement})\n")
855:     else
856:       error = Gem::LoadError.new(
857:           "RubyGem version error: " +
858:           "#{gem.name}(#{matches.first.version} not #{gem.requirement})\n")
859:     end
860: 
861:     error.name = gem.name
862:     error.requirement = gem.requirement
863:     raise error
864:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.