Namespace

Class Index [+]

Quicksearch

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

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

RubyGemsVersion
ConfigMap

Configuration settings from ::RbConfig

DIRECTORIES

Default directories in a gem repository

WIN_PATTERNS

An Array of Regexps that match windows ruby platforms.

MARSHAL_SPEC_DIR

Location of Marshal quick gemspecs on remote repositories

YAML_SPEC_DIR

Location of legacy YAML quick gemspecs on remote repositories

Attributes

ssl_available[W]

Is SSL available?

loaded_specs[R]

Hash of loaded Gem::Specification keyed by name

post_install_hooks[R]

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

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_uninstall_hooks[R]

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

Public Class Methods

activate(gem, *version_requirements) click to toggle source

Activates an installed gem matching gem. The gem must satisfy version_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 gem 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 200
200:   def self.activate(gem, *version_requirements)
201:     if version_requirements.last.is_a?(Hash)
202:       options = version_requirements.pop
203:     else
204:       options = {}
205:     end
206: 
207:     sources = options[:sources] || []
208: 
209:     if version_requirements.empty? then
210:       version_requirements = Gem::Requirement.default
211:     end
212: 
213:     unless gem.respond_to?(:name) and
214:            gem.respond_to?(:requirement) then
215:       gem = Gem::Dependency.new(gem, version_requirements)
216:     end
217: 
218:     matches = Gem.source_index.find_name(gem.name, gem.requirement)
219:     report_activate_error(gem) if matches.empty?
220: 
221:     if @loaded_specs[gem.name] then
222:       # This gem is already loaded.  If the currently loaded gem is not in the
223:       # list of candidate gems, then we have a version conflict.
224:       existing_spec = @loaded_specs[gem.name]
225: 
226:       unless matches.any? { |spec| spec.version == existing_spec.version } then
227:          sources_message = sources.map { |spec| spec.full_name }
228:          stack_message = @loaded_stacks[gem.name].map { |spec| spec.full_name }
229: 
230:          msg = "can't activate #{gem} for #{sources_message.inspect}, "
231:          msg << "already activated #{existing_spec.full_name} for "
232:          msg << "#{stack_message.inspect}"
233: 
234:          e = Gem::LoadError.new msg
235:          e.name = gem.name
236:          e.version_requirement = gem.requirement
237: 
238:          raise e
239:       end
240: 
241:       return false
242:     end
243: 
244:     # new load
245:     spec = matches.last
246:     return false if spec.loaded?
247: 
248:     spec.loaded = true
249:     @loaded_specs[spec.name] = spec
250:     @loaded_stacks[spec.name] = sources.dup
251: 
252:     # Load dependent gems first
253:     spec.runtime_dependencies.each do |dep_gem|
254:       activate dep_gem, :sources => [spec, *sources]
255:     end
256: 
257:     # bin directory must come before library directories
258:     spec.require_paths.unshift spec.bindir if spec.bindir
259: 
260:     require_paths = spec.require_paths.map do |path|
261:       File.join spec.full_gem_path, path
262:     end
263: 
264:     # gem directories must come after -I and ENV['RUBYLIB']
265:     insert_index = load_path_insert_index
266: 
267:     if insert_index then
268:       # gem directories must come after -I and ENV['RUBYLIB']
269:       $LOAD_PATH.insert(insert_index, *require_paths)
270:     else
271:       # we are probably testing in core, -I and RUBYLIB don't apply
272:       $LOAD_PATH.unshift(*require_paths)
273:     end
274: 
275:     return true
276:   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 282
282:   def self.all_load_paths
283:     result = []
284: 
285:     Gem.path.each do |gemdir|
286:       each_load_path all_partials(gemdir) do |load_path|
287:         result << load_path
288:       end
289:     end
290: 
291:     result
292:   end
available?(gem, *requirements) click to toggle source

See if a given gem is available.

     # File lib/rubygems.rb, line 306
306:   def self.available?(gem, *requirements)
307:     requirements = Gem::Requirement.default if requirements.empty?
308: 
309:     unless gem.respond_to?(:name) and
310:            gem.respond_to?(:requirement) then
311:       gem = Gem::Dependency.new gem, requirements
312:     end
313: 
314:     !Gem.source_index.search(gem).empty?
315:   end
bin_path(name, exec_name = nil, *version_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. version_requirements allows you to specify specific gem versions.

     # File lib/rubygems.rb, line 323
323:   def self.bin_path(name, exec_name = nil, *version_requirements)
324:     version_requirements = Gem::Requirement.default if
325:       version_requirements.empty?
326:     spec = Gem.source_index.find_name(name, version_requirements).last
327: 
328:     raise Gem::GemNotFoundException,
329:           "can't find gem #{name} (#{version_requirements})" unless spec
330: 
331:     exec_name ||= spec.default_executable
332: 
333:     unless exec_name
334:       msg = "no default executable for #{spec.full_name}"
335:       raise Gem::Exception, msg
336:     end
337: 
338:     unless spec.executables.include? exec_name
339:       msg = "can't find executable #{exec_name} for #{spec.full_name}"
340:       raise Gem::Exception, msg
341:     end
342: 
343:     File.join(spec.full_gem_path, spec.bindir, exec_name)
344:   end
binary_mode() click to toggle source

The mode needed to read a file as straight binary.

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

The path where gem executables are to be installed.

     # File lib/rubygems.rb, line 356
356:   def self.bindir(install_dir=Gem.dir)
357:     return File.join(install_dir, 'bin') unless
358:       install_dir.to_s == Gem.default_dir
359:     Gem.default_bindir
360:   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 367
367:   def self.clear_paths
368:     @gem_home = nil
369:     @gem_path = nil
370:     @user_home = nil
371: 
372:     @@source_index = nil
373: 
374:     MUTEX.synchronize do
375:       @searcher = nil
376:     end
377:   end
config_file() click to toggle source

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

     # File lib/rubygems.rb, line 382
382:   def self.config_file
383:     File.join Gem.user_home, '.gemrc'
384:   end
configuration() click to toggle source

The standard configuration object for gems.

     # File lib/rubygems.rb, line 389
389:   def self.configuration
390:     @configuration ||= Gem::ConfigFile.new []
391:   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 397
397:   def self.configuration=(config)
398:     @configuration = config
399:   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 405
405:   def self.datadir(gem_name)
406:     spec = @loaded_specs[gem_name]
407:     return nil if spec.nil?
408:     File.join(spec.full_gem_path, 'data', gem_name)
409:   end
default_bindir() click to toggle source

The default directory for binaries

    # File lib/rubygems/defaults.rb, line 67
67:   def self.default_bindir
68:     if defined? RUBY_FRAMEWORK_VERSION then # mac framework support
69:       '/usr/bin'
70:     else # generic install
71:       ConfigMap[:bindir]
72:     end
73:   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 19
19:   def self.default_dir
20:     if defined? RUBY_FRAMEWORK_VERSION then
21:       File.join File.dirname(ConfigMap[:sitedir]), 'Gems',
22:                 ConfigMap[:ruby_version]
23:     elsif ConfigMap[:rubylibprefix] then
24:       File.join(ConfigMap[:rubylibprefix], 'gems',
25:                 ConfigMap[:ruby_version])
26:     else
27:       File.join(ConfigMap[:libdir], ruby_engine, 'gems',
28:                 ConfigMap[:ruby_version])
29:     end
30:   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 53
53:   def self.default_exec_format
54:     exec_format = ConfigMap[:ruby_install_name].sub('ruby', '%s') rescue '%s'
55: 
56:     unless exec_format =~ /%s/ then
57:       raise Gem::Exception,
58:         "[BUG] invalid exec_format #{exec_format.inspect}, no %s"
59:     end
60: 
61:     exec_format
62:   end
default_path() click to toggle source

Default gem load path

    # File lib/rubygems/defaults.rb, line 42
42:   def self.default_path
43:     if File.exist? Gem.user_home then
44:       [user_dir, default_dir]
45:     else
46:       [default_dir]
47:     end
48:   end
default_sources() click to toggle source

An Array of the default sources that come with RubyGems

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

The default system-wide source info cache directory

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

The default user-specific source info cache directory

    # File lib/rubygems/defaults.rb, line 85
85:   def self.default_user_source_cache_dir
86:     File.join Gem.user_home, '.gem', 'source_cache'
87:   end
deflate(data) click to toggle source

A Zlib::Deflate.deflate wrapper

     # File lib/rubygems.rb, line 414
414:   def self.deflate(data)
415:     require 'zlib'
416:     Zlib::Deflate.deflate data
417:   end
dir() click to toggle source

The path where gems are to be installed.

     # File lib/rubygems.rb, line 422
422:   def self.dir
423:     @gem_home ||= nil
424:     set_home(ENV['GEM_HOME'] || Gem.configuration.home || default_dir) unless @gem_home
425:     @gem_home
426:   end
ensure_gem_subdirectories(gemdir) 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 455
455:   def self.ensure_gem_subdirectories(gemdir)
456:     require 'fileutils'
457: 
458:     Gem::DIRECTORIES.each do |filename|
459:       fn = File.join gemdir, filename
460:       FileUtils.mkdir_p fn rescue nil unless File.exist? fn
461:     end
462:   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(path) click to toggle source

Returns a list of paths matching file 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

find_files search $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 475
475:   def self.find_files(path)
476:     load_path_files = $LOAD_PATH.map do |load_path|
477:       files = Dir["#{File.expand_path path, load_path}#{Gem.suffix_pattern}"]
478: 
479:       files.select do |load_path_file|
480:         File.file? load_path_file.untaint
481:       end
482:     end.flatten
483: 
484:     specs = searcher.find_all path
485: 
486:     specs_files = specs.map do |spec|
487:       searcher.matching_files spec, path
488:     end.flatten
489: 
490:     (load_path_files + specs_files).flatten.uniq
491:   end
gunzip(data) click to toggle source

Zlib::GzipReader wrapper that unzips data.

     # File lib/rubygems.rb, line 511
511:   def self.gunzip(data)
512:     require 'stringio'
513:     require 'zlib'
514:     data = StringIO.new data
515: 
516:     Zlib::GzipReader.new(data).read
517:   end
gzip(data) click to toggle source

Zlib::GzipWriter wrapper that zips data.

     # File lib/rubygems.rb, line 522
522:   def self.gzip(data)
523:     require 'stringio'
524:     require 'zlib'
525:     zipped = StringIO.new
526: 
527:     Zlib::GzipWriter.wrap zipped do |io| io.write data end
528: 
529:     zipped.string
530:   end
inflate(data) click to toggle source

A Zlib::Inflate#inflate wrapper

     # File lib/rubygems.rb, line 535
535:   def self.inflate(data)
536:     require 'zlib'
537:     Zlib::Inflate.inflate data
538:   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 544
544:   def self.latest_load_paths
545:     result = []
546: 
547:     Gem.path.each do |gemdir|
548:       each_load_path(latest_partials(gemdir)) do |load_path|
549:         result << load_path
550:       end
551:     end
552: 
553:     result
554:   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 583
583:   def self.load_path_insert_index
584:     $LOAD_PATH.index { |p| p.instance_variable_defined? :@gem_prelude_index }
585:   end
load_plugins() click to toggle source

Find all ‘rubygems_plugin’ files and load them

     # File lib/rubygems.rb, line 965
965:   def self.load_plugins
966:     plugins = Gem.find_files 'rubygems_plugin'
967: 
968:     plugins.each do |plugin|
969: 
970:       # Skip older versions of the GemCutter plugin: Its commands are in
971:       # RubyGems proper now.
972: 
973:       next if plugin =~ /gemcutter-0\.[0-3]/
974: 
975:       begin
976:         load plugin
977:       rescue ::Exception => e
978:         details = "#{plugin.inspect}: #{e.message} (#{e.class})"
979:         warn "Error loading RubyGems plugin #{details}"
980:       end
981:     end
982:   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 596
596:   def self.location_of_caller
597:     caller[1] =~ /(.*?):(\d+).*?$/
598:     file = $1
599:     lineno = $2.to_i
600: 
601:     [file, lineno]
602:   end
marshal_version() click to toggle source

The version of the Marshal format for your Ruby.

     # File lib/rubygems.rb, line 607
607:   def self.marshal_version
608:     "#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}"
609:   end
path() click to toggle source

Array of paths to search for Gems.

     # File lib/rubygems.rb, line 614
614:   def self.path
615:     @gem_path ||= nil
616: 
617:     unless @gem_path then
618:       paths = [ENV['GEM_PATH'] || Gem.configuration.path || default_path]
619: 
620:       if defined?(APPLE_GEM_HOME) and not ENV['GEM_PATH'] then
621:         paths << APPLE_GEM_HOME
622:       end
623: 
624:       set_paths paths.compact.join(File::PATH_SEPARATOR)
625:     end
626: 
627:     @gem_path
628:   end
platforms() click to toggle source

Array of platforms this RubyGems supports.

     # File lib/rubygems.rb, line 640
640:   def self.platforms
641:     @platforms ||= []
642:     if @platforms.empty?
643:       @platforms = [Gem::Platform::RUBY, Gem::Platform.local]
644:     end
645:     @platforms
646:   end
platforms=(platforms) click to toggle source

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

     # File lib/rubygems.rb, line 633
633:   def self.platforms=(platforms)
634:     @platforms = platforms
635:   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 652
652:   def self.post_install(&hook)
653:     @post_install_hooks << hook
654:   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 661
661:   def self.post_uninstall(&hook)
662:     @post_uninstall_hooks << hook
663:   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

     # File lib/rubygems.rb, line 669
669:   def self.pre_install(&hook)
670:     @pre_install_hooks << hook
671:   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 678
678:   def self.pre_uninstall(&hook)
679:     @pre_uninstall_hooks << hook
680:   end
prefix() click to toggle source

The directory prefix this RubyGems was installed at.

     # File lib/rubygems.rb, line 685
685:   def self.prefix
686:     dir = File.dirname File.expand_path(__FILE__)
687:     prefix = File.dirname dir
688: 
689:     if prefix == File.expand_path(ConfigMap[:sitelibdir]) or
690:        prefix == File.expand_path(ConfigMap[:libdir]) or
691:        'lib' != File.basename(dir) then
692:       nil
693:     else
694:       prefix
695:     end
696:   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 703
703:   def self.promote_load_path(gem_name, over_name)
704:     gem = Gem.loaded_specs[gem_name]
705:     over = Gem.loaded_specs[over_name]
706: 
707:     raise ArgumentError, "gem #{gem_name} is not activated" if gem.nil?
708:     raise ArgumentError, "gem #{over_name} is not activated" if over.nil?
709: 
710:     last_gem_path = File.join gem.full_gem_path, gem.require_paths.last
711: 
712:     over_paths = over.require_paths.map do |path|
713:       File.join over.full_gem_path, path
714:     end
715: 
716:     over_paths.each do |path|
717:       $LOAD_PATH.delete path
718:     end
719: 
720:     gem = $LOAD_PATH.index(last_gem_path) + 1
721: 
722:     $LOAD_PATH.insert(gem, *over_paths)
723:   end
read_binary(path) click to toggle source

Safely read a file in binary mode on all platforms.

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

Refresh source_index from disk and clear searcher.

     # File lib/rubygems.rb, line 728
728:   def self.refresh
729:     source_index.refresh!
730: 
731:     MUTEX.synchronize do
732:       @searcher = nil
733:     end
734:   end
remove_prelude_paths() click to toggle source
     # File lib/rubygems.rb, line 587
587:   def self.remove_prelude_paths
588:     Gem::QuickLoader::GemLoadPaths.each do |path|
589:       $LOAD_PATH.delete(path)
590:     end
591:   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 771
771:   def self.required_location(gemname, libfile, *requirements)
772:     requirements = Gem::Requirement.default if requirements.empty?
773: 
774:     matches = Gem.source_index.find_name gemname, requirements
775: 
776:     return nil if matches.empty?
777: 
778:     spec = matches.last
779:     spec.require_paths.each do |path|
780:       result = File.join spec.full_gem_path, path, libfile
781:       return result if File.exist? result
782:     end
783: 
784:     nil
785:   end
ruby() click to toggle source

The path to the running Ruby interpreter.

     # File lib/rubygems.rb, line 790
790:   def self.ruby
791:     if @ruby.nil? then
792:       @ruby = File.join(ConfigMap[:bindir],
793:                         ConfigMap[:ruby_install_name])
794:       @ruby << ConfigMap[:EXEEXT]
795: 
796:       # escape string in case path to ruby executable contain spaces.
797:       @ruby.sub!(/.*\s.*/, '"\&"')
798:     end
799: 
800:     @ruby
801:   end
ruby_engine() click to toggle source

A wrapper around RUBY_ENGINE const that may not be defined

    # File lib/rubygems/defaults.rb, line 92
92:   def self.ruby_engine
93:     if defined? RUBY_ENGINE then
94:       RUBY_ENGINE
95:     else
96:       'ruby'
97:     end
98:   end
ruby_version() click to toggle source

A Gem::Version for the currently running ruby.

     # File lib/rubygems.rb, line 806
806:   def self.ruby_version
807:     return @ruby_version if defined? @ruby_version
808:     version = RUBY_VERSION.dup
809: 
810:     if defined?(RUBY_PATCHLEVEL) && RUBY_PATCHLEVEL != 1 then
811:       version << ".#{RUBY_PATCHLEVEL}"
812:     elsif defined?(RUBY_REVISION) then
813:       version << ".dev.#{RUBY_REVISION}"
814:     end
815: 
816:     @ruby_version = Gem::Version.new version
817:   end
searcher() click to toggle source

The GemPathSearcher object used to search for matching installed gems.

     # File lib/rubygems.rb, line 822
822:   def self.searcher
823:     MUTEX.synchronize do
824:       @searcher ||= Gem::GemPathSearcher.new
825:     end
826:   end
source_index() click to toggle source

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

     # File lib/rubygems.rb, line 865
865:   def self.source_index
866:     @@source_index ||= SourceIndex.from_installed_gems
867:   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 874
874:   def self.sources
875:     if @sources.empty? then
876:       begin
877:         gem 'sources', '> 0.0.1'
878:         require 'sources'
879:       rescue LoadError
880:         @sources = default_sources
881:       end
882:     end
883: 
884:     @sources
885:   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 891
891:   def self.sources=(new_sources)
892:     @sources = new_sources
893:   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 898
898:   def self.suffix_pattern
899:     @suffix_pattern ||= "{#{suffixes.join(',')}}"
900:   end
suffixes() click to toggle source

Suffixes for require-able paths.

     # File lib/rubygems.rb, line 905
905:   def self.suffixes
906:     ['', '.rb', '.rbw', '.so', '.bundle', '.dll', '.sl', '.jar']
907:   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 913
913:   def self.time(msg, width = 0, display = Gem.configuration.verbose)
914:     now = Time.now
915: 
916:     value = yield
917: 
918:     elapsed = Time.now - now
919: 
920:     ui.say "%2$*1$s: %3$3.3fs" % [-width, msg, elapsed] if display
921: 
922:     value
923:   end
try_activate(path) click to toggle source
      # File lib/rubygems.rb, line 1115
1115:   def try_activate(path)
1116:     spec = Gem.searcher.find(path)
1117:     return false unless spec
1118: 
1119:     Gem.activate(spec.name, "= #{spec.version}")
1120:     return true
1121:   end
ui() click to toggle source

Lazily loads DefaultUserInteraction and returns the default UI.

     # File lib/rubygems.rb, line 928
928:   def self.ui
929:     require 'rubygems/user_interaction'
930: 
931:     Gem::DefaultUserInteraction.ui
932:   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 938
938:   def self.use_paths(home, paths=[])
939:     clear_paths
940:     set_home(home) if home
941:     set_paths(paths.join(File::PATH_SEPARATOR)) if paths
942:   end
user_dir() click to toggle source

Path for gems in the user’s home directory

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

The home directory for the user.

     # File lib/rubygems.rb, line 947
947:   def self.user_home
948:     @user_home ||= find_home
949:   end
win_platform?() click to toggle source

Is this a windows platform?

     # File lib/rubygems.rb, line 954
954:   def self.win_platform?
955:     if @@win_platform.nil? then
956:       @@win_platform = !!WIN_PATTERNS.find { |r| RUBY_PLATFORM =~ r }
957:     end
958: 
959:     @@win_platform
960:   end

Private Class Methods

all_partials(gemdir) click to toggle source

Return all the partial paths in gemdir.

     # File lib/rubygems.rb, line 297
297:   def self.all_partials(gemdir)
298:     Dir[File.join(gemdir, 'gems/*')]
299:   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 432
432:   def self.each_load_path(partials)
433:     partials.each do |gp|
434:       base = File.basename(gp)
435:       specfn = File.join(dir, "specifications", base + ".gemspec")
436:       if File.exist?(specfn)
437:         spec = eval(File.read(specfn))
438:         spec.require_paths.each do |rp|
439:           yield(File.join(gp, rp))
440:         end
441:       else
442:         filename = File.join(gp, 'lib')
443:         yield(filename) if File.exist?(filename)
444:       end
445:     end
446:   end
find_home() click to toggle source

Finds the user’s home directory.

     # File lib/rubygems.rb, line 496
496:   def self.find_home
497:     File.expand_path "~"
498:   rescue
499:     if File::ALT_SEPARATOR then
500:       "C:/"
501:     else
502:       "/"
503:     end
504:   end
latest_partials(gemdir) click to toggle source

Return only the latest partial paths in the given gemdir.

     # File lib/rubygems.rb, line 559
559:   def self.latest_partials(gemdir)
560:     latest = {}
561:     all_partials(gemdir).each do |gp|
562:       base = File.basename(gp)
563:       if base =~ /(.*)-((\d+\.)*\d+)/ then
564:         name, version = $1, $2
565:         ver = Gem::Version.new(version)
566:         if latest[name].nil? || ver > latest[name][0]
567:           latest[name] = [ver, gp]
568:         end
569:       end
570:     end
571:     latest.collect { |k,v| v[1] }
572:   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 748
748:   def self.report_activate_error(gem)
749:     matches = Gem.source_index.find_name(gem.name)
750: 
751:     if matches.empty? then
752:       error = Gem::LoadError.new(
753:           "Could not find RubyGem #{gem.name} (#{gem.requirement})\n")
754:     else
755:       error = Gem::LoadError.new(
756:           "RubyGem version error: " +
757:           "#{gem.name}(#{matches.first.version} not #{gem.requirement})\n")
758:     end
759: 
760:     error.name = gem.name
761:     error.version_requirement = gem.requirement
762:     raise error
763:   end
set_home(home) click to toggle source

Set the Gem home directory (as reported by Gem.dir).

     # File lib/rubygems.rb, line 831
831:   def self.set_home(home)
832:     home = home.gsub File::ALT_SEPARATOR, File::SEPARATOR if File::ALT_SEPARATOR
833:     @gem_home = home
834:   end
set_paths(gpaths) click to toggle source

Set the Gem search path (as reported by Gem.path).

     # File lib/rubygems.rb, line 841
841:   def self.set_paths(gpaths)
842:     if gpaths
843:       @gem_path = gpaths.split(File::PATH_SEPARATOR)
844: 
845:       if File::ALT_SEPARATOR then
846:         @gem_path.map! do |path|
847:           path.gsub File::ALT_SEPARATOR, File::SEPARATOR
848:         end
849:       end
850: 
851:       @gem_path << Gem.dir
852:     else
853:       # TODO: should this be Gem.default_path instead?
854:       @gem_path = [Gem.dir]
855:     end
856: 
857:     @gem_path.uniq!
858:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.