Main module to hold all RubyGem classes/modules.
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. |
== | -> | eql? |
loaded_specs | [R] | |
ssl_available | [W] | Set the value of the ssl_avilable flag. |
Load custom marshal format, re-initializing defaults as needed
# 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.
# 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.
# 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.
# 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
# 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 reader method behaves like this:
def attribute @attribute ||= (copy of default value) end
This allows lazy initialization of attributes to their default values.
# 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
# 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
# File lib/rubygems/specification.rb, line 104 104: def self.attribute_defaults 105: @@attributes.dup 106: end
————————- Convenience class methods.
# 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).
# 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.
# File lib/rubygems.rb, line 209 209: def self.binary_mode 210: @binary_mode ||= RUBY_VERSION > '1.9' ? 'rb:ascii-8bit' : 'rb' 211: 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.
# 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 standard configuration object for gems.
# 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.
# 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.
# 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
# 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)
# File lib/rubygems/defaults.rb, line 16 16: def self.default_dir 17: File.join('/', 'var', 'lib', 'gems', ConfigMap[:ruby_version]) 18: end
The default system-wide source info cache directory.
# 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.
# 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
# File lib/rubygems/specification.rb, line 108 108: def self.default_value(name) 109: @@default_value[name] 110: 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.
# 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
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.
# 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.
# 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
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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
The directory prefix this RubyGems was installed at.
# 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
Refresh source_index from disk and clear searcher.
# 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
# File lib/rubygems/specification.rb, line 116 116: def self.required_attribute?(name) 117: @@required_attributes.include? name.to_sym 118: end
# File lib/rubygems/specification.rb, line 112 112: def self.required_attributes 113: @@required_attributes.dup 114: end
# 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
A Gem::Version for the currently running ruby.
# 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.
# 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
# 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.
# 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
Suffixes for require-able paths.
# 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.
# 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.
# File lib/rubygems.rb, line 659 659: def self.user_home 660: @user_home ||= find_home 661: end
Is this a windows platform?
# 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
# 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. |
# 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.
# 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]]] |
# 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.
# File lib/rubygems/specification.rb, line 687 687: def file_name 688: full_name + ".gem" 689: end
# 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 |
# 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).
# 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
Predicates ——————————————————
# File lib/rubygems/specification.rb, line 521 521: def loaded?; @loaded ? true : false ; end
Sets the rubygems_version to Gem::RubyGemsVersion.
# File lib/rubygems/specification.rb, line 618 618: def mark_version 619: @rubygems_version = RubyGemsVersion 620: end
Normalize the list of files so that:
Also, the summary and description are converted to a normal format.
# 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.
# 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
# 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 |
# 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 ———————————————
# 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 ———————————-
# 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
# 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.
# 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
# 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..
# 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