Module Gem
In: lib/rubygems/builder.rb
lib/rubygems/command.rb
lib/rubygems/command_manager.rb
lib/rubygems/commands/list_command.rb
lib/rubygems/commands/rdoc_command.rb
lib/rubygems/commands/search_command.rb
lib/rubygems/commands/uninstall_command.rb
lib/rubygems/defaults.rb
lib/rubygems/digest/digest_adapter.rb
lib/rubygems/digest/sha1.rb
lib/rubygems/digest/sha2.rb
lib/rubygems/doc_manager.rb
lib/rubygems/format.rb
lib/rubygems/gem_openssl.rb
lib/rubygems/gem_runner.rb
lib/rubygems/old_format.rb
lib/rubygems/require_paths_builder.rb
lib/rubygems/rubygems_version.rb
lib/rubygems/source_index.rb
lib/rubygems/specification.rb
lib/rubygems/user_interaction.rb
lib/rubygems/validator.rb
lib/rubygems.rb

Main module to hold all RubyGem classes/modules.

Methods

Classes and Modules

Module Gem::Commands
Module Gem::DefaultUserInteraction
Module Gem::Ext
Module Gem::Indexer
Module Gem::InstallUpdateOptions
Module Gem::LocalRemoteOptions
Module Gem::Package
Module Gem::RequirePathsBuilder
Module Gem::SSL
Module Gem::Security
Module Gem::UserInteraction
Module Gem::VersionOption
Class Gem::Builder
Class Gem::Command
Class Gem::CommandLineError
Class Gem::CommandManager
Class Gem::ConfigFile
Class Gem::ConsoleUI
Class Gem::Dependency
Class Gem::DependencyError
Class Gem::DependencyInstaller
Class Gem::DependencyList
Class Gem::DependencyRemovalException
Class Gem::DigestAdapter
Class Gem::DocManager
Class Gem::DocumentError
Class Gem::EndOfYAMLException
Class Gem::Exception
Class Gem::FileOperations
Class Gem::FilePermissionError
Class Gem::Format
Class Gem::FormatException
Class Gem::GemNotFoundException
Class Gem::GemNotInHomeException
Class Gem::GemPathSearcher
Class Gem::GemRunner
Class Gem::Indexer
Class Gem::InstallError
Class Gem::Installer
Class Gem::InvalidSpecificationException
Class Gem::LoadError
Class Gem::OldFormat
Class Gem::OperationNotSupportedError
Class Gem::Platform
Class Gem::RemoteError
Class Gem::RemoteFetcher
Class Gem::RemoteInstallationCancelled
Class Gem::RemoteInstallationSkipped
Class Gem::RemoteSourceException
Class Gem::Requirement
Class Gem::Server
Class Gem::SilentUI
Class Gem::SourceIndex
Class Gem::SourceInfoCache
Class Gem::SourceInfoCacheEntry
Class Gem::StreamUI
Class Gem::SystemExitException
Class Gem::Uninstaller
Class Gem::Validator
Class Gem::VerificationError
Class Gem::Version

Constants

SHA1 = Digest::SHA1
SHA1 = DigestAdapter.new(Digest::SHA1)
SHA256 = Digest::SHA256
SHA256 = DigestAdapter.new(Digest::SHA256)
RubyGemsVersion = '1.1.1'
ConfigMap = {} unless defined?(ConfigMap)
RbConfig = Config unless defined? ::RbConfig
DIRECTORIES = %w[cache doc gems specifications] unless defined?(DIRECTORIES)
MUTEX = Mutex.new
RubyGemsPackageVersion = RubyGemsVersion
WIN_PATTERNS = [ /bccwin/i, /cygwin/i, /djgpp/i, /mingw/i, /mswin/i, /wince/i, ]   An Array of Regexps that match windows ruby platforms.

External Aliases

== -> eql?

Attributes

loaded_specs  [R] 
ssl_available  [W]  Set the value of the ssl_avilable flag.

Public Class methods

Load custom marshal format, re-initializing defaults as needed

[Source]

     # File lib/rubygems/specification.rb, line 260
260:     def self._load(str)
261:       array = Marshal.load str
262: 
263:       spec = Gem::Specification.new
264:       spec.instance_variable_set :@specification_version, array[1]
265: 
266:       current_version = CURRENT_SPECIFICATION_VERSION
267: 
268:       field_count = MARSHAL_FIELDS[spec.specification_version]
269: 
270:       if field_count.nil? or array.size < field_count then
271:         raise TypeError, "invalid Gem::Specification format #{array.inspect}"
272:       end
273: 
274:       spec.instance_variable_set :@rubygems_version,          array[0]
275:       # spec version
276:       spec.instance_variable_set :@name,                      array[2]
277:       spec.instance_variable_set :@version,                   array[3]
278:       spec.instance_variable_set :@date,                      array[4]
279:       spec.instance_variable_set :@summary,                   array[5]
280:       spec.instance_variable_set :@required_ruby_version,     array[6]
281:       spec.instance_variable_set :@required_rubygems_version, array[7]
282:       spec.instance_variable_set :@original_platform,         array[8]
283:       spec.instance_variable_set :@dependencies,              array[9]
284:       spec.instance_variable_set :@rubyforge_project,         array[10]
285:       spec.instance_variable_set :@email,                     array[11]
286:       spec.instance_variable_set :@authors,                   array[12]
287:       spec.instance_variable_set :@description,               array[13]
288:       spec.instance_variable_set :@homepage,                  array[14]
289:       spec.instance_variable_set :@has_rdoc,                  array[15]
290:       spec.instance_variable_set :@new_platform,              array[16]
291:       spec.instance_variable_set :@platform,                  array[16].to_s
292:       spec.instance_variable_set :@loaded,                    false
293: 
294:       spec
295:     end

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.

[Source]

     # File lib/rubygems.rb, line 120
120:   def self.activate(gem, *version_requirements)
121:     if version_requirements.empty? then
122:       version_requirements = Gem::Requirement.default
123:     end
124: 
125:     unless gem.respond_to?(:name) and
126:            gem.respond_to?(:version_requirements) then
127:       gem = Gem::Dependency.new(gem, version_requirements)
128:     end
129: 
130:     matches = Gem.source_index.find_name(gem.name, gem.version_requirements)
131:     report_activate_error(gem) if matches.empty?
132: 
133:     if @loaded_specs[gem.name] then
134:       # This gem is already loaded.  If the currently loaded gem is not in the
135:       # list of candidate gems, then we have a version conflict.
136:       existing_spec = @loaded_specs[gem.name]
137: 
138:       unless matches.any? { |spec| spec.version == existing_spec.version } then
139:         raise Gem::Exception,
140:               "can't activate #{gem}, already activated #{existing_spec.full_name}]"
141:       end
142: 
143:       return false
144:     end
145: 
146:     # new load
147:     spec = matches.last
148:     return false if spec.loaded?
149: 
150:     spec.loaded = true
151:     @loaded_specs[spec.name] = spec
152: 
153:     # Load dependent gems first
154:     spec.dependencies.each do |dep_gem|
155:       activate dep_gem
156:     end
157: 
158:     # bin directory must come before library directories
159:     spec.require_paths.unshift spec.bindir if spec.bindir
160: 
161:     require_paths = spec.require_paths.map do |path|
162:       File.join spec.full_gem_path, path
163:     end
164: 
165:     sitelibdir = ConfigMap[:sitelibdir]
166: 
167:     # gem directories must come after -I and ENV['RUBYLIB']
168:     insert_index = load_path_insert_index
169: 
170:     if insert_index then
171:       # gem directories must come after -I and ENV['RUBYLIB']
172:       $LOAD_PATH.insert(insert_index, *require_paths)
173:     else
174:       # we are probably testing in core, -I and RUBYLIB don't apply
175:       $LOAD_PATH.unshift(*require_paths)
176:     end
177: 
178:     return true
179:   end

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

[Source]

     # File lib/rubygems.rb, line 185
185:   def self.all_load_paths
186:     result = []
187: 
188:     Gem.path.each do |gemdir|
189:       each_load_path all_partials(gemdir) do |load_path|
190:         result << load_path
191:       end
192:     end
193: 
194:     result
195:   end

Same as :attribute, but ensures that values assigned to the attribute are array values by applying :to_a to the value.

[Source]

     # File lib/rubygems/specification.rb, line 161
161:     def self.array_attribute(name)
162:       @@non_nil_attributes << ["@#{name}".intern, []]
163: 
164:       @@array_attributes << name
165:       @@attributes << [name, []]
166:       @@default_value[name] = []
167:       code = %{
168:         def #{name}
169:           @#{name} ||= []
170:         end
171:         def #{name}=(value)
172:           @#{name} = Array(value)
173:         end
174:       }
175: 
176:       module_eval code, __FILE__, __LINE__ - 9
177:     end

[Source]

     # File lib/rubygems/specification.rb, line 120
120:     def self.array_attributes
121:       @@array_attributes.dup
122:     end

Used to specify the name and default value of a specification attribute. The side effects are:

  • the name and default value are added to the @@attributes list and @@default_value map
  • a standard writer method (attribute=) is created
  • a non-standard _reader method (attribute) is created

The reader method behaves like this:

  def attribute
    @attribute ||= (copy of default value)
  end

This allows lazy initialization of attributes to their default values.

[Source]

     # File lib/rubygems/specification.rb, line 146
146:     def self.attribute(name, default=nil)
147:       ivar_name = "@#{name}".intern
148:       if default.nil? then
149:         @@nil_attributes << ivar_name
150:       else
151:         @@non_nil_attributes << [ivar_name, default]
152:       end
153: 
154:       @@attributes << [name, default]
155:       @@default_value[name] = default
156:       attr_accessor(name)
157:     end

Defines a singular version of an existing plural attribute (i.e. one whose value is expected to be an array). This means just creating a helper method that takes a single value and appends it to the array. These are created for convenience, so that in a spec, one can write

  s.require_path = 'mylib'

instead of

  s.require_paths = ['mylib']

That above convenience is available courtesy of

  attribute_alias_singular :require_path, :require_paths

[Source]

     # File lib/rubygems/specification.rb, line 224
224:     def self.attribute_alias_singular(singular, plural)
225:       define_method("#{singular}=") { |val|
226:         send("#{plural}=", [val])
227:       }
228:       define_method("#{singular}") { 
229:         val = send("#{plural}")
230:         val.nil? ? nil : val.first
231:       }
232:     end

[Source]

     # File lib/rubygems/specification.rb, line 104
104:     def self.attribute_defaults
105:       @@attributes.dup
106:     end

————————- Convenience class methods.

[Source]

     # File lib/rubygems/specification.rb, line 100
100:     def self.attribute_names
101:       @@attributes.map { |name, default| name }
102:     end

Shortcut for creating several attributes at once (each with a default value of nil).

[Source]

     # File lib/rubygems/specification.rb, line 195
195:     def self.attributes(*args)
196:       args.each do |arg|
197:         attribute(arg, nil)
198:       end
199:     end

The mode needed to read a file as straight binary.

[Source]

     # File lib/rubygems.rb, line 209
209:   def self.binary_mode
210:     @binary_mode ||= RUBY_VERSION > '1.9' ? 'rb:ascii-8bit' : 'rb'
211:   end

The path where gem executables are to be installed.

[Source]

     # File lib/rubygems.rb, line 216
216:   def self.bindir(install_dir=Gem.dir)
217:     return File.join(install_dir, 'bin') unless
218:       install_dir.to_s == Gem.default_dir
219:     Gem.default_bindir
220:   end

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.

[Source]

     # File lib/rubygems.rb, line 227
227:   def self.clear_paths
228:     @gem_home = nil
229:     @gem_path = nil
230:     @@source_index = nil
231:     MUTEX.synchronize do
232:       @searcher = nil
233:     end
234:   end

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

[Source]

     # File lib/rubygems.rb, line 239
239:   def self.config_file
240:     File.join Gem.user_home, '.gemrc'
241:   end

The standard configuration object for gems.

[Source]

     # File lib/rubygems.rb, line 246
246:   def self.configuration
247:     return @configuration if @configuration
248:     require 'rubygems/config_file'
249:     @configuration = Gem::ConfigFile.new []
250:   end

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

[Source]

     # File lib/rubygems.rb, line 256
256:   def self.configuration=(config)
257:     @configuration = config
258:   end

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

[Source]

     # File lib/rubygems.rb, line 264
264:   def self.datadir(gem_name)
265:     spec = @loaded_specs[gem_name]
266:     return nil if spec.nil?
267:     File.join(spec.full_gem_path, 'data', gem_name)
268:   end

The default directory for binaries Debian patch:

  /var/lib/gems/{ruby version}/bin is the default path in Debian system

[Source]

    # File lib/rubygems/defaults.rb, line 34
34:   def self.default_bindir
35:     File.join('/', 'var', 'lib', 'gems', ConfigMap[:ruby_version], 'bin')
36:   end

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

Debian patch: search order of this directory.

  1. GEM_HOME enviroment variable
     (Using this, Gems are to be installed in any path as you like)
  2. /var/lib/gems/{ruby version} (This is the default path in Debian system)

[Source]

    # File lib/rubygems/defaults.rb, line 16
16:   def self.default_dir
17:     File.join('/', 'var', 'lib', 'gems', ConfigMap[:ruby_version])
18:   end

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

[Source]

    # File lib/rubygems/defaults.rb, line 26
26:   def self.default_exec_format
27:     baseruby = ConfigMap[:BASERUBY] || 'ruby'
28:     ConfigMap[:RUBY_INSTALL_NAME].sub(baseruby, '%s') rescue '%s'
29:   end

Default gem path.

[Source]

    # File lib/rubygems/defaults.rb, line 21
21:   def self.default_path
22:     default_dir
23:   end

An Array of the default sources that come with RubyGems.

[Source]

   # File lib/rubygems/defaults.rb, line 4
4:   def self.default_sources
5:     %w[http://gems.rubyforge.org]
6:   end

The default system-wide source info cache directory.

[Source]

    # File lib/rubygems/defaults.rb, line 39
39:   def self.default_system_source_cache_dir
40:     File.join Gem.dir, 'source_cache'
41:   end

The default user-specific source info cache directory.

[Source]

    # File lib/rubygems/defaults.rb, line 44
44:   def self.default_user_source_cache_dir
45:     File.join Gem.user_home, '.gem', 'source_cache'
46:   end

[Source]

     # File lib/rubygems/specification.rb, line 108
108:     def self.default_value(name)
109:       @@default_value[name]
110:     end

The path where gems are to be installed.

[Source]

     # File lib/rubygems.rb, line 273
273:   def self.dir
274:     @gem_home ||= nil
275:     set_home(ENV['GEM_HOME'] || default_dir) unless @gem_home
276:     @gem_home
277:   end

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.

[Source]

     # File lib/rubygems.rb, line 306
306:   def self.ensure_gem_subdirectories(gemdir)
307:     require 'fileutils'
308: 
309:     Gem::DIRECTORIES.each do |filename|
310:       fn = File.join gemdir, filename
311:       FileUtils.mkdir_p fn rescue nil unless File.exist? fn
312:     end
313:   end

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

[Source]

    # File lib/rubygems/gem_openssl.rb, line 24
24:     def ensure_ssl_available
25:       unless ssl_available?
26:         fail Gem::Exception, "SSL is not installed on this system"
27:       end
28:     end

Special loader for YAML files. When a Specification object is loaded from a YAML file, it bypasses the normal Ruby object initialization routine (initialize). This method makes up for that and deals with gems of different ages.

‘input’ can be anything that YAML.load() accepts: String or IO.

[Source]

     # File lib/rubygems/specification.rb, line 574
574:     def self.from_yaml(input)
575:       input = normalize_yaml_input input
576:       spec = YAML.load input
577: 
578:       if spec && spec.class == FalseClass then
579:         raise Gem::EndOfYAMLException
580:       end
581: 
582:       unless Gem::Specification === spec then
583:         raise Gem::Exception, "YAML data doesn't evaluate to gem specification"
584:       end
585: 
586:       unless (spec.instance_variables.include? '@specification_version' or
587:               spec.instance_variables.include? :@specification_version) and
588:              spec.instance_variable_get :@specification_version
589:         spec.instance_variable_set :@specification_version, 
590:                                    NONEXISTENT_SPECIFICATION_VERSION
591:       end
592: 
593:       spec
594:     end

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

[Source]

     # File lib/rubygems.rb, line 352
352:   def self.latest_load_paths
353:     result = []
354: 
355:     Gem.path.each do |gemdir|
356:       each_load_path(latest_partials(gemdir)) do |load_path|
357:         result << load_path
358:       end
359:     end
360: 
361:     result
362:   end

A list of Specification instances that have been defined in this Ruby instance.

[Source]

     # File lib/rubygems/specification.rb, line 127
127:     def self.list
128:       @@list
129:     end

[Source]

     # File lib/rubygems/specification.rb, line 596
596:     def self.load(filename)
597:       gemspec = nil
598:       fail "NESTED Specification.load calls not allowed!" if @@gather
599:       @@gather = proc { |gs| gemspec = gs }
600:       data = File.read(filename)
601:       eval(data)
602:       gemspec
603:     ensure
604:       @@gather = nil
605:     end

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.

[Source]

     # File lib/rubygems.rb, line 391
391:   def self.load_path_insert_index
392:     index = $LOAD_PATH.index ConfigMap[:sitelibdir]
393: 
394:     $LOAD_PATH.each_with_index do |path, i|
395:       if path.instance_variables.include?(:@gem_prelude_index) or
396:         path.instance_variables.include?('@gem_prelude_index') then
397:         index = i
398:         break
399:       end
400:     end
401: 
402:     index
403:   end

manage_gems is useless and deprecated. Don‘t call it anymore.

[Source]

     # File lib/rubygems.rb, line 421
421:   def self.manage_gems
422:     #file, lineno = location_of_caller
423: 
424:     #warn "#{file}:#{lineno}:Warning: Gem#manage_gems is deprecated and will be removed on or after September 2008."
425:   end

The version of the Marshal format for your Ruby.

[Source]

     # File lib/rubygems.rb, line 430
430:   def self.marshal_version
431:     "#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}"
432:   end

Specification constructor. Assigns the default values to the attributes, adds this spec to the list of loaded specs (see Specification.list), and yields itself for further initialization.

[Source]

     # File lib/rubygems/specification.rb, line 532
532:     def initialize
533:       @new_platform = nil
534:       assign_defaults
535:       @loaded = false
536:       @loaded_from = nil
537:       @@list << self
538: 
539:       yield self if block_given?
540: 
541:       @@gather.call(self) if @@gather
542:     end

Make sure the yaml specification is properly formatted with dashes.

[Source]

     # File lib/rubygems/specification.rb, line 608
608:     def self.normalize_yaml_input(input)
609:       result = input.respond_to?(:read) ? input.read : input
610:       result = "--- " + result unless result =~ /^--- /
611:       result
612:     end

Some attributes require special behaviour when they are accessed. This allows for that.

[Source]

     # File lib/rubygems/specification.rb, line 203
203:     def self.overwrite_accessor(name, &block)
204:       remove_method name
205:       define_method(name, &block)
206:     end

Array of paths to search for Gems.

[Source]

     # File lib/rubygems.rb, line 437
437:   def self.path
438:     @gem_path ||= nil
439: 
440:     unless @gem_path then
441:       paths = [ENV['GEM_PATH']] || [default_path]
442: 
443:       if defined?(APPLE_GEM_HOME) and not ENV['GEM_PATH'] then
444:         paths << APPLE_GEM_HOME
445:       end
446: 
447:       set_paths paths.compact.join(File::PATH_SEPARATOR)
448:     end
449: 
450:     @gem_path
451:   end

Array of platforms this RubyGems supports.

[Source]

     # File lib/rubygems.rb, line 463
463:   def self.platforms
464:     @platforms ||= []
465:     if @platforms.empty?
466:       @platforms = [Gem::Platform::RUBY, Gem::Platform.local]
467:     end
468:     @platforms
469:   end

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

[Source]

     # File lib/rubygems.rb, line 456
456:   def self.platforms=(platforms)
457:     @platforms = platforms
458:   end

The directory prefix this RubyGems was installed at.

[Source]

     # File lib/rubygems.rb, line 474
474:   def self.prefix
475:     prefix = File.dirname File.expand_path(__FILE__)
476: 
477:     if File.dirname(prefix) == File.expand_path(ConfigMap[:sitelibdir]) or
478:        File.dirname(prefix) == File.expand_path(ConfigMap[:libdir]) or
479:        'lib' != File.basename(prefix) then
480:       nil
481:     else
482:       File.dirname prefix
483:     end
484:   end

Safely read a file in binary mode on all platforms.

[Source]

     # File lib/rubygems.rb, line 500
500:   def self.read_binary(path)
501:     File.open path, binary_mode do |f| f.read end
502:   end

Sometimes we don‘t want the world to use a setter method for a particular attribute. read_only makes it private so we can still use it internally.

[Source]

     # File lib/rubygems/specification.rb, line 187
187:     def self.read_only(*names)
188:       names.each do |name|
189:         private "#{name}="
190:       end
191:     end

Refresh source_index from disk and clear searcher.

[Source]

     # File lib/rubygems.rb, line 489
489:   def self.refresh
490:     source_index.refresh!
491: 
492:     MUTEX.synchronize do
493:       @searcher = nil
494:     end
495:   end

Same as attribute above, but also records this attribute as mandatory.

[Source]

     # File lib/rubygems/specification.rb, line 180
180:     def self.required_attribute(*args)
181:       @@required_attributes << args.first
182:       attribute(*args)
183:     end

[Source]

     # File lib/rubygems/specification.rb, line 116
116:     def self.required_attribute?(name)
117:       @@required_attributes.include? name.to_sym
118:     end

[Source]

     # File lib/rubygems/specification.rb, line 112
112:     def self.required_attributes
113:       @@required_attributes.dup
114:     end

[Source]

     # File lib/rubygems.rb, line 528
528:   def self.required_location(gemname, libfile, *version_constraints)
529:     version_constraints = Gem::Requirement.default if version_constraints.empty?
530:     matches = Gem.source_index.find_name(gemname, version_constraints)
531:     return nil if matches.empty?
532:     spec = matches.last
533:     spec.require_paths.each do |path|
534:       result = File.join(spec.full_gem_path, path, libfile)
535:       return result if File.exist?(result)
536:     end
537:     nil
538:   end

The path to the running Ruby interpreter.

[Source]

     # File lib/rubygems.rb, line 543
543:   def self.ruby
544:     if @ruby.nil? then
545:       @ruby = File.join(ConfigMap[:bindir],
546:                         ConfigMap[:ruby_install_name])
547:       @ruby << ConfigMap[:EXEEXT]
548:     end
549: 
550:     @ruby
551:   end

A Gem::Version for the currently running ruby.

[Source]

     # File lib/rubygems.rb, line 556
556:   def self.ruby_version
557:     return @ruby_version if defined? @ruby_version
558:     version = RUBY_VERSION.dup
559:     version << ".#{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL
560:     @ruby_version = Gem::Version.new version
561:   end

The GemPathSearcher object used to search for matching installed gems.

[Source]

     # File lib/rubygems.rb, line 566
566:   def self.searcher
567:     MUTEX.synchronize do
568:       @searcher ||= Gem::GemPathSearcher.new
569:     end
570:   end

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

[Source]

     # File lib/rubygems.rb, line 610
610:   def self.source_index
611:     @@source_index ||= SourceIndex.from_installed_gems
612:   end

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.

[Source]

     # File lib/rubygems.rb, line 619
619:   def self.sources
620:     if @sources.empty? then
621:       begin
622:         gem 'sources', '> 0.0.1'
623:         require 'sources'
624:       rescue LoadError
625:         @sources = default_sources
626:       end
627:     end
628: 
629:     @sources
630:   end

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

[Source]

    # File lib/rubygems/gem_openssl.rb, line 15
15:     def ssl_available?
16:       require 'rubygems/gem_openssl'
17:       @ssl_available
18:     end

Glob pattern for require-able path suffixes.

[Source]

     # File lib/rubygems.rb, line 635
635:   def self.suffix_pattern
636:     @suffix_pattern ||= "{#{suffixes.join(',')}}"
637:   end

Suffixes for require-able paths.

[Source]

     # File lib/rubygems.rb, line 642
642:   def self.suffixes
643:     ['', '.rb', '.rbw', '.so', '.bundle', '.dll', '.sl', '.jar']
644:   end

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

[Source]

     # File lib/rubygems.rb, line 650
650:   def self.use_paths(home, paths=[])
651:     clear_paths
652:     set_home(home) if home
653:     set_paths(paths.join(File::PATH_SEPARATOR)) if paths
654:   end

The home directory for the user.

[Source]

     # File lib/rubygems.rb, line 659
659:   def self.user_home
660:     @user_home ||= find_home
661:   end

Is this a windows platform?

[Source]

     # File lib/rubygems.rb, line 666
666:   def self.win_platform?
667:     if @@win_platform.nil? then
668:       @@win_platform = !!WIN_PATTERNS.find { |r| RUBY_PLATFORM =~ r }
669:     end
670: 
671:     @@win_platform
672:   end

Public Instance methods

[Source]

     # File lib/rubygems/specification.rb, line 473
473:     def add_bindir(executables)
474:       return nil if executables.nil?
475: 
476:       if @bindir then
477:         Array(executables).map { |e| File.join(@bindir, e) }
478:       else
479:         executables
480:       end
481:     rescue
482:       return nil
483:     end

Adds a dependency to this Gem. For example,

  spec.add_dependency('jabber4r', '> 0.1', '<= 0.5')
gem:[String or Gem::Dependency] The Gem name/dependency.
requirements:[default=">= 0"] The version requirements.

[Source]

     # File lib/rubygems/specification.rb, line 639
639:     def add_dependency(gem, *requirements)
640:       requirements = if requirements.empty? then
641:                        Gem::Requirement.default
642:                      else
643:                        requirements.flatten
644:                      end
645: 
646:       unless gem.respond_to?(:name) && gem.respond_to?(:version_requirements)
647:         gem = Dependency.new(gem, requirements)
648:       end
649: 
650:       dependencies << gem
651:     end

Each attribute has a default value (possibly nil). Here, we initialize all attributes to their default value. This is done through the accessor methods, so special behaviours will be honored. Furthermore, we take a copy of the default so each specification instance has its own empty arrays, etc.

[Source]

     # File lib/rubygems/specification.rb, line 549
549:     def assign_defaults
550:       @@nil_attributes.each do |name|
551:         instance_variable_set name, nil
552:       end
553: 
554:       @@non_nil_attributes.each do |name, default|
555:         value = case default
556:                 when Time, Numeric, Symbol, true, false, nil then default
557:                 else default.dup
558:                 end
559: 
560:         instance_variable_set name, value
561:       end
562: 
563:       # HACK
564:       instance_variable_set :@new_platform, Gem::Platform::RUBY
565:     end

Return a list of all gems that have a dependency on this gemspec. The list is structured with entries that conform to:

  [depending_gem, dependency, [list_of_gems_that_satisfy_dependency]]
return:[Array] [[dependent_gem, dependency, [list_of_satisfiers]]]

[Source]

     # File lib/rubygems/specification.rb, line 921
921:     def dependent_gems
922:       out = []
923:       Gem.source_index.each do |name,gem|
924:         gem.dependencies.each do |dep|
925:           if self.satisfies_requirement?(dep) then
926:             sats = []
927:             find_all_satisfiers(dep) do |sat|
928:               sats << sat
929:             end
930:             out << [gem, dep, sats]
931:           end
932:         end
933:       end
934:       out
935:     end

The default (generated) file name of the gem.

[Source]

     # File lib/rubygems/specification.rb, line 687
687:     def file_name
688:       full_name + ".gem"
689:     end

[Source]

     # File lib/rubygems/specification.rb, line 943
943:     def find_all_satisfiers(dep)
944:       Gem.source_index.each do |name,gem|
945:         if(gem.satisfies_requirement?(dep)) then
946:           yield gem
947:         end
948:       end
949:     end

The full path to the gem (install path + full name).

return:[String] the full gem path

[Source]

     # File lib/rubygems/specification.rb, line 680
680:     def full_gem_path
681:       path = File.join installation_path, 'gems', full_name
682:       return path if File.directory? path
683:       File.join installation_path, 'gems', original_name
684:     end

Returns the full name (name-version) of this Gem. Platform information is included (name-version-platform) if it is specified (and not the default Ruby platform).

[Source]

     # File lib/rubygems/specification.rb, line 657
657:     def full_name
658:       if platform == Gem::Platform::RUBY or platform.nil? then
659:         "#{@name}-#{@version}"
660:       else
661:         "#{@name}-#{@version}-#{platform}"
662:       end
663:     end

[Source]

     # File lib/rubygems/specification.rb, line 522
522:     def has_rdoc?; has_rdoc ? true : false ; end
has_test_suite?()

Alias for has_unit_tests?

[Source]

     # File lib/rubygems/specification.rb, line 523
523:     def has_unit_tests?; not test_files.empty?; end

The root directory that the gem was installed into.

return:[String] the installation path

[Source]

     # File lib/rubygems/specification.rb, line 695
695:     def installation_path
696:       (File.dirname(@loaded_from).split(File::SEPARATOR)[0..-2]).
697:         join(File::SEPARATOR)
698:     end

Files in the Gem under one of the require_paths

[Source]

     # File lib/rubygems/specification.rb, line 496
496:     def lib_files
497:       @files.select do |file|
498:         require_paths.any? do |path|
499:           file.index(path) == 0
500:         end
501:       end
502:     end

Predicates ——————————————————

[Source]

     # File lib/rubygems/specification.rb, line 521
521:     def loaded?; @loaded ? true : false ; end

Sets the rubygems_version to Gem::RubyGemsVersion.

[Source]

     # File lib/rubygems/specification.rb, line 618
618:     def mark_version
619:       @rubygems_version = RubyGemsVersion
620:     end

Normalize the list of files so that:

  • All file lists have redundancies removed.
  • Files referenced in the extra_rdoc_files are included in the package file list.

Also, the summary and description are converted to a normal format.

[Source]

     # File lib/rubygems/specification.rb, line 903
903:     def normalize
904:       if defined?(@extra_rdoc_files) and @extra_rdoc_files then
905:         @extra_rdoc_files.uniq!
906:         @files ||= []
907:         @files.concat(@extra_rdoc_files)
908:       end
909:       @files.uniq! if @files
910:     end

Return a string containing a Ruby code representation of the given object.

[Source]

     # File lib/rubygems/specification.rb, line 953
953:     def ruby_code(obj)
954:       case obj
955:       when String            then '%q{' + obj + '}'
956:       when Array             then obj.inspect
957:       when Gem::Version      then obj.to_s.inspect
958:       when Date              then '%q{' + obj.strftime('%Y-%m-%d') + '}'
959:       when Time              then '%q{' + obj.strftime('%Y-%m-%d') + '}'
960:       when Numeric           then obj.inspect
961:       when true, false, nil  then obj.inspect
962:       when Gem::Platform     then "Gem::Platform.new(#{obj.to_a.inspect})"
963:       when Gem::Requirement  then "Gem::Requirement.new(#{obj.to_s.inspect})"
964:       else raise Exception, "ruby_code case not handled: #{obj.class}"
965:       end
966:     end

[Source]

     # File lib/rubygems/specification.rb, line 728
728:     def same_attributes?(other)
729:       @@attributes.each do |name, default|
730:         return false unless self.send(name) == other.send(name)
731:       end
732:       true
733:     end

Checks if this Specification meets the requirement of the supplied dependency.

dependency:[Gem::Dependency] the dependency to check
return:[Boolean] true if dependency is met, otherwise false

[Source]

     # File lib/rubygems/specification.rb, line 706
706:     def satisfies_requirement?(dependency)
707:       return @name == dependency.name && 
708:         dependency.version_requirements.satisfied_by?(@version)
709:     end

Comparison methods ———————————————

[Source]

     # File lib/rubygems/specification.rb, line 713
713:     def sort_obj
714:       [@name, @version.to_ints, @new_platform == Gem::Platform::RUBY ? -1 : 1]
715:     end

DEPRECATED gemspec attributes ———————————-

[Source]

     # File lib/rubygems/specification.rb, line 347
347:     def test_suite_file
348:       warn 'test_suite_file deprecated, use test_files'
349:       test_files.first
350:     end

[Source]

     # File lib/rubygems/specification.rb, line 352
352:     def test_suite_file=(val)
353:       warn 'test_suite_file= deprecated, use test_files='
354:       @test_files = [] unless defined? @test_files
355:       @test_files << val
356:     end

Returns a Ruby code representation of this specification, such that it can be eval‘ed and reconstruct the same specification later. Attributes that still have their default values are omitted.

[Source]

     # File lib/rubygems/specification.rb, line 784
784:     def to_ruby
785:       mark_version
786:       result = []
787:       result << "Gem::Specification.new do |s|"
788: 
789:       result << "  s.name = #{ruby_code name}"
790:       result << "  s.version = #{ruby_code version}"
791:       unless platform.nil? or platform == Gem::Platform::RUBY then
792:         result << "  s.platform = #{ruby_code original_platform}"
793:       end
794:       result << ""
795:       result << "  s.specification_version = #{specification_version} if s.respond_to? :specification_version="
796:       result << ""
797:       result << "  s.required_rubygems_version = #{ruby_code required_rubygems_version} if s.respond_to? :required_rubygems_version="
798: 
799:       handled = [
800:         :dependencies,
801:         :name,
802:         :platform,
803:         :required_rubygems_version,
804:         :specification_version,
805:         :version,
806:       ]
807: 
808:       attributes = @@attributes.sort_by { |attr_name,| attr_name.to_s }
809: 
810:       attributes.each do |attr_name, default|
811:         next if handled.include? attr_name
812:         current_value = self.send(attr_name)
813:         if current_value != default or
814:            self.class.required_attribute? attr_name then
815:           result << "  s.#{attr_name} = #{ruby_code current_value}"
816:         end
817:       end
818: 
819:       result << "" unless dependencies.empty?
820: 
821:       dependencies.each do |dep|
822:         version_reqs_param = dep.requirements_list.inspect
823:         result << "  s.add_dependency(%q<#{dep.name}>, #{version_reqs_param})"
824:       end
825: 
826:       result << "end"
827:       result << ""
828: 
829:       result.join "\n"
830:     end

[Source]

     # File lib/rubygems/specification.rb, line 937
937:     def to_s
938:       "#<Gem::Specification name=#{@name} version=#{@version}>"
939:     end

Checks that the specification contains all required fields, and does a very basic sanity check.

Raises InvalidSpecificationException if the spec does not pass the checks..

[Source]

     # File lib/rubygems/specification.rb, line 839
839:     def validate
840:       extend Gem::UserInteraction
841: 
842:       normalize
843: 
844:       if rubygems_version != RubyGemsVersion then
845:         raise Gem::InvalidSpecificationException,
846:               "expected RubyGems version #{RubyGemsVersion}, was #{rubygems_version}"
847:       end
848: 
849:       @@required_attributes.each do |symbol|
850:         unless self.send symbol then
851:           raise Gem::InvalidSpecificationException,
852:                 "missing value for attribute #{symbol}"
853:         end
854:       end 
855: 
856:       if require_paths.empty? then
857:         raise Gem::InvalidSpecificationException,
858:               "specification must have at least one require_path"
859:       end
860: 
861:       case platform
862:       when Gem::Platform, Platform::RUBY then # ok
863:       else
864:         raise Gem::InvalidSpecificationException,
865:               "invalid platform #{platform.inspect}, see Gem::Platform"
866:       end
867: 
868:       unless Array === authors and
869:              authors.all? { |author| String === author } then
870:         raise Gem::InvalidSpecificationException,
871:               'authors must be Array of Strings'
872:       end
873: 
874:       # Warnings
875: 
876:       %w[author email homepage rubyforge_project summary].each do |attribute|
877:         value = self.send attribute
878:         alert_warning "no #{attribute} specified" if value.nil? or value.empty?
879:       end
880: 
881:       alert_warning "RDoc will not be generated (has_rdoc == false)" unless
882:         has_rdoc
883: 
884:       alert_warning "deprecated autorequire specified" if autorequire
885: 
886:       executables.each do |executable|
887:         executable_path = File.join bindir, executable
888:         shebang = File.read(executable_path, 2) == '#!'
889: 
890:         alert_warning "#{executable_path} is missing #! line" unless shebang
891:       end
892: 
893:       true
894:     end

[Validate]