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.2.0' | ||
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. | |
MARSHAL_SPEC_DIR | = | "quick/Marshal.#{Gem.marshal_version}/" | ||
YAML_SPEC_DIR | = | 'quick/' |
== | -> | eql? |
loaded_specs | [R] | |
ssl_available | [W] | Set the value of the ssl_available flag. |
Load custom marshal format, re-initializing defaults as needed
# File lib/rubygems/specification.rb, line 280 280: def self._load(str) 281: array = Marshal.load str 282: 283: spec = Gem::Specification.new 284: spec.instance_variable_set :@specification_version, array[1] 285: 286: current_version = CURRENT_SPECIFICATION_VERSION 287: 288: field_count = if spec.specification_version > current_version then 289: spec.instance_variable_set :@specification_version, 290: current_version 291: MARSHAL_FIELDS[current_version] 292: else 293: MARSHAL_FIELDS[spec.specification_version] 294: end 295: 296: if array.size < field_count then 297: raise TypeError, "invalid Gem::Specification format #{array.inspect}" 298: end 299: 300: spec.instance_variable_set :@rubygems_version, array[0] 301: # spec version 302: spec.instance_variable_set :@name, array[2] 303: spec.instance_variable_set :@version, array[3] 304: spec.instance_variable_set :@date, array[4] 305: spec.instance_variable_set :@summary, array[5] 306: spec.instance_variable_set :@required_ruby_version, array[6] 307: spec.instance_variable_set :@required_rubygems_version, array[7] 308: spec.instance_variable_set :@original_platform, array[8] 309: spec.instance_variable_set :@dependencies, array[9] 310: spec.instance_variable_set :@rubyforge_project, array[10] 311: spec.instance_variable_set :@email, array[11] 312: spec.instance_variable_set :@authors, array[12] 313: spec.instance_variable_set :@description, array[13] 314: spec.instance_variable_set :@homepage, array[14] 315: spec.instance_variable_set :@has_rdoc, array[15] 316: spec.instance_variable_set :@new_platform, array[16] 317: spec.instance_variable_set :@platform, array[16].to_s 318: spec.instance_variable_set :@loaded, false 319: 320: spec 321: 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 123 123: def self.activate(gem, *version_requirements) 124: if version_requirements.empty? then 125: version_requirements = Gem::Requirement.default 126: end 127: 128: unless gem.respond_to?(:name) and 129: gem.respond_to?(:version_requirements) then 130: gem = Gem::Dependency.new(gem, version_requirements) 131: end 132: 133: matches = Gem.source_index.find_name(gem.name, gem.version_requirements) 134: report_activate_error(gem) if matches.empty? 135: 136: if @loaded_specs[gem.name] then 137: # This gem is already loaded. If the currently loaded gem is not in the 138: # list of candidate gems, then we have a version conflict. 139: existing_spec = @loaded_specs[gem.name] 140: 141: unless matches.any? { |spec| spec.version == existing_spec.version } then 142: raise Gem::Exception, 143: "can't activate #{gem}, already activated #{existing_spec.full_name}" 144: end 145: 146: return false 147: end 148: 149: # new load 150: spec = matches.last 151: return false if spec.loaded? 152: 153: spec.loaded = true 154: @loaded_specs[spec.name] = spec 155: 156: # Load dependent gems first 157: spec.runtime_dependencies.each do |dep_gem| 158: activate dep_gem 159: end 160: 161: # bin directory must come before library directories 162: spec.require_paths.unshift spec.bindir if spec.bindir 163: 164: require_paths = spec.require_paths.map do |path| 165: File.join spec.full_gem_path, path 166: end 167: 168: sitelibdir = ConfigMap[:sitelibdir] 169: 170: # gem directories must come after -I and ENV['RUBYLIB'] 171: insert_index = load_path_insert_index 172: 173: if insert_index then 174: # gem directories must come after -I and ENV['RUBYLIB'] 175: $LOAD_PATH.insert(insert_index, *require_paths) 176: else 177: # we are probably testing in core, -I and RUBYLIB don't apply 178: $LOAD_PATH.unshift(*require_paths) 179: end 180: 181: return true 182: end
An Array of all possible load paths for all versions of all gems in the Gem installation.
# File lib/rubygems.rb, line 188 188: def self.all_load_paths 189: result = [] 190: 191: Gem.path.each do |gemdir| 192: each_load_path all_partials(gemdir) do |load_path| 193: result << load_path 194: end 195: end 196: 197: result 198: 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 177 177: def self.array_attribute(name) 178: @@non_nil_attributes << ["@#{name}".intern, []] 179: 180: @@array_attributes << name 181: @@attributes << [name, []] 182: @@default_value[name] = [] 183: code = %{ 184: def #{name} 185: @#{name} ||= [] 186: end 187: def #{name}=(value) 188: @#{name} = Array(value) 189: end 190: } 191: 192: module_eval code, __FILE__, __LINE__ - 9 193: end
# File lib/rubygems/specification.rb, line 136 136: def self.array_attributes 137: @@array_attributes.dup 138: 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 162 162: def self.attribute(name, default=nil) 163: ivar_name = "@#{name}".intern 164: if default.nil? then 165: @@nil_attributes << ivar_name 166: else 167: @@non_nil_attributes << [ivar_name, default] 168: end 169: 170: @@attributes << [name, default] 171: @@default_value[name] = default 172: attr_accessor(name) 173: 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 240 240: def self.attribute_alias_singular(singular, plural) 241: define_method("#{singular}=") { |val| 242: send("#{plural}=", [val]) 243: } 244: define_method("#{singular}") { 245: val = send("#{plural}") 246: val.nil? ? nil : val.first 247: } 248: end
# File lib/rubygems/specification.rb, line 120 120: def self.attribute_defaults 121: @@attributes.dup 122: end
————————- Convenience class methods.
# File lib/rubygems/specification.rb, line 116 116: def self.attribute_names 117: @@attributes.map { |name, default| name } 118: end
Shortcut for creating several attributes at once (each with a default value of nil).
# File lib/rubygems/specification.rb, line 211 211: def self.attributes(*args) 212: args.each do |arg| 213: attribute(arg, nil) 214: end 215: end
See if a given gem is available.
# File lib/rubygems.rb, line 212 212: def self.available?(gem, *requirements) 213: requirements = Gem::Requirement.default if requirements.empty? 214: 215: unless gem.respond_to?(:name) and 216: gem.respond_to?(:version_requirements) then 217: gem = Gem::Dependency.new gem, requirements 218: end 219: 220: !Gem.source_index.search(gem).empty? 221: end
The mode needed to read a file as straight binary.
# File lib/rubygems.rb, line 226 226: def self.binary_mode 227: @binary_mode ||= RUBY_VERSION > '1.9' ? 'rb:ascii-8bit' : 'rb' 228: 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 244 244: def self.clear_paths 245: @gem_home = nil 246: @gem_path = nil 247: @@source_index = nil 248: MUTEX.synchronize do 249: @searcher = nil 250: end 251: end
The standard configuration object for gems.
# File lib/rubygems.rb, line 263 263: def self.configuration 264: return @configuration if @configuration 265: require 'rubygems/config_file' 266: @configuration = Gem::ConfigFile.new [] 267: end
Use the given configuration object (which implements the ConfigFile protocol) as the standard configuration object.
# File lib/rubygems.rb, line 273 273: def self.configuration=(config) 274: @configuration = config 275: 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 281 281: def self.datadir(gem_name) 282: spec = @loaded_specs[gem_name] 283: return nil if spec.nil? 284: File.join(spec.full_gem_path, 'data', gem_name) 285: 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 124 124: def self.default_value(name) 125: @@default_value[name] 126: end
A Zlib::Deflate.deflate wrapper
# File lib/rubygems.rb, line 290 290: def self.deflate(data) 291: Zlib::Deflate.deflate data 292: 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 330 330: def self.ensure_gem_subdirectories(gemdir) 331: require 'fileutils' 332: 333: Gem::DIRECTORIES.each do |filename| 334: fn = File.join gemdir, filename 335: FileUtils.mkdir_p fn rescue nil unless File.exist? fn 336: end 337: 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 608 608: def self.from_yaml(input) 609: input = normalize_yaml_input input 610: spec = YAML.load input 611: 612: if spec && spec.class == FalseClass then 613: raise Gem::EndOfYAMLException 614: end 615: 616: unless Gem::Specification === spec then 617: raise Gem::Exception, "YAML data doesn't evaluate to gem specification" 618: end 619: 620: unless (spec.instance_variables.include? '@specification_version' or 621: spec.instance_variables.include? :@specification_version) and 622: spec.instance_variable_get :@specification_version 623: spec.instance_variable_set :@specification_version, 624: NONEXISTENT_SPECIFICATION_VERSION 625: end 626: 627: spec 628: end
Zlib::GzipReader wrapper that unzips data.
# File lib/rubygems.rb, line 375 375: def self.gunzip(data) 376: data = StringIO.new data 377: 378: Zlib::GzipReader.new(data).read 379: end
Zlib::GzipWriter wrapper that zips data.
# File lib/rubygems.rb, line 384 384: def self.gzip(data) 385: zipped = StringIO.new 386: 387: Zlib::GzipWriter.wrap zipped do |io| io.write data end 388: 389: zipped.string 390: end
A Zlib::Inflate#inflate wrapper
# File lib/rubygems.rb, line 395 395: def self.inflate(data) 396: Zlib::Inflate.inflate data 397: 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 403 403: def self.latest_load_paths 404: result = [] 405: 406: Gem.path.each do |gemdir| 407: each_load_path(latest_partials(gemdir)) do |load_path| 408: result << load_path 409: end 410: end 411: 412: result 413: end
# File lib/rubygems/specification.rb, line 630 630: def self.load(filename) 631: gemspec = nil 632: fail "NESTED Specification.load calls not allowed!" if @@gather 633: @@gather = proc { |gs| gemspec = gs } 634: data = File.read(filename) 635: eval(data) 636: gemspec 637: ensure 638: @@gather = nil 639: 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 442 442: def self.load_path_insert_index 443: index = $LOAD_PATH.index ConfigMap[:sitelibdir] 444: 445: $LOAD_PATH.each_with_index do |path, i| 446: if path.instance_variables.include?(:@gem_prelude_index) or 447: path.instance_variables.include?('@gem_prelude_index') then 448: index = i 449: break 450: end 451: end 452: 453: index 454: end
manage_gems is useless and deprecated. Don‘t call it anymore.
# File lib/rubygems.rb, line 472 472: def self.manage_gems 473: #file, lineno = location_of_caller 474: 475: #warn "#{file}:#{lineno}:Warning: Gem#manage_gems is deprecated and will be removed on or after September 2008." 476: end
The version of the Marshal format for your Ruby.
# File lib/rubygems.rb, line 481 481: def self.marshal_version 482: "#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}" 483: 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 566 566: def initialize 567: @new_platform = nil 568: assign_defaults 569: @loaded = false 570: @loaded_from = nil 571: @@list << self 572: 573: yield self if block_given? 574: 575: @@gather.call(self) if @@gather 576: end
Make sure the yaml specification is properly formatted with dashes.
# File lib/rubygems/specification.rb, line 642 642: def self.normalize_yaml_input(input) 643: result = input.respond_to?(:read) ? input.read : input 644: result = "--- " + result unless result =~ /^--- / 645: result 646: end
Some attributes require special behaviour when they are accessed. This allows for that.
# File lib/rubygems/specification.rb, line 219 219: def self.overwrite_accessor(name, &block) 220: remove_method name 221: define_method(name, &block) 222: end
Array of paths to search for Gems.
# File lib/rubygems.rb, line 488 488: def self.path 489: @gem_path ||= nil 490: 491: unless @gem_path then 492: paths = if ENV['GEM_PATH'] then 493: [ENV['GEM_PATH']] 494: else 495: [default_path] 496: end 497: 498: if defined?(APPLE_GEM_HOME) and not ENV['GEM_PATH'] then 499: paths << APPLE_GEM_HOME 500: end 501: 502: set_paths paths.compact.join(File::PATH_SEPARATOR) 503: end 504: 505: @gem_path 506: end
The directory prefix this RubyGems was installed at.
# File lib/rubygems.rb, line 529 529: def self.prefix 530: prefix = File.dirname File.expand_path(__FILE__) 531: 532: if File.dirname(prefix) == File.expand_path(ConfigMap[:sitelibdir]) or 533: File.dirname(prefix) == File.expand_path(ConfigMap[:libdir]) or 534: 'lib' != File.basename(prefix) then 535: nil 536: else 537: File.dirname prefix 538: end 539: end
Refresh source_index from disk and clear searcher.
# File lib/rubygems.rb, line 544 544: def self.refresh 545: source_index.refresh! 546: 547: MUTEX.synchronize do 548: @searcher = nil 549: end 550: end
# File lib/rubygems/specification.rb, line 132 132: def self.required_attribute?(name) 133: @@required_attributes.include? name.to_sym 134: end
# File lib/rubygems/specification.rb, line 128 128: def self.required_attributes 129: @@required_attributes.dup 130: end
# File lib/rubygems.rb, line 583 583: def self.required_location(gemname, libfile, *version_constraints) 584: version_constraints = Gem::Requirement.default if version_constraints.empty? 585: matches = Gem.source_index.find_name(gemname, version_constraints) 586: return nil if matches.empty? 587: spec = matches.last 588: spec.require_paths.each do |path| 589: result = File.join(spec.full_gem_path, path, libfile) 590: return result if File.exist?(result) 591: end 592: nil 593: end
A Gem::Version for the currently running ruby.
# File lib/rubygems.rb, line 611 611: def self.ruby_version 612: return @ruby_version if defined? @ruby_version 613: version = RUBY_VERSION.dup 614: version << ".#{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL 615: @ruby_version = Gem::Version.new version 616: end
The GemPathSearcher object used to search for matching installed gems.
# File lib/rubygems.rb, line 621 621: def self.searcher 622: MUTEX.synchronize do 623: @searcher ||= Gem::GemPathSearcher.new 624: end 625: end
Returns the Gem::SourceIndex of specifications that are in the Gem.path
# File lib/rubygems.rb, line 665 665: def self.source_index 666: @@source_index ||= SourceIndex.from_installed_gems 667: 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 674 674: def self.sources 675: if @sources.empty? then 676: begin 677: gem 'sources', '> 0.0.1' 678: require 'sources' 679: rescue LoadError 680: @sources = default_sources 681: end 682: end 683: 684: @sources 685: end
Suffixes for require-able paths.
# File lib/rubygems.rb, line 697 697: def self.suffixes 698: ['', '.rb', '.rbw', '.so', '.bundle', '.dll', '.sl', '.jar'] 699: 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 705 705: def self.use_paths(home, paths=[]) 706: clear_paths 707: set_home(home) if home 708: set_paths(paths.join(File::PATH_SEPARATOR)) if paths 709: end
The home directory for the user.
# File lib/rubygems.rb, line 714 714: def self.user_home 715: @user_home ||= find_home 716: end
Is this a windows platform?
# File lib/rubygems.rb, line 721 721: def self.win_platform? 722: if @@win_platform.nil? then 723: @@win_platform = !!WIN_PATTERNS.find { |r| RUBY_PLATFORM =~ r } 724: end 725: 726: @@win_platform 727: end
Dump only crucial instance variables.
# File lib/rubygems/specification.rb, line 255 255: def _dump(limit) 256: Marshal.dump [ 257: @rubygems_version, 258: @specification_version, 259: @name, 260: @version, 261: (Time === @date ? @date : (require 'time'; Time.parse(@date.to_s))), 262: @summary, 263: @required_ruby_version, 264: @required_rubygems_version, 265: @original_platform, 266: @dependencies, 267: @rubyforge_project, 268: @email, 269: @authors, 270: @description, 271: @homepage, 272: @has_rdoc, 273: @new_platform, 274: ] 275: end
# File lib/rubygems/specification.rb, line 507 507: def add_bindir(executables) 508: return nil if executables.nil? 509: 510: if @bindir then 511: Array(executables).map { |e| File.join(@bindir, e) } 512: else 513: executables 514: end 515: rescue 516: return nil 517: end
# File lib/rubygems/specification.rb, line 1009 1009: def add_dependency_with_type(dependency, type, *requirements) 1010: requirements = if requirements.empty? then 1011: Gem::Requirement.default 1012: else 1013: requirements.flatten 1014: end 1015: 1016: unless dependency.respond_to?(:name) && 1017: dependency.respond_to?(:version_requirements) 1018: 1019: dependency = Dependency.new(dependency, requirements, type) 1020: end 1021: 1022: dependencies << dependency 1023: end
Adds a development dependency to this Gem. For example,
spec.add_development_dependency('jabber4r', '> 0.1', '<= 0.5')
Development dependencies aren‘t installed by default, and aren‘t activated when a gem is required.
gem: | [String or Gem::Dependency] The Gem name/dependency. |
requirements: | [default=">= 0"] The version requirements. |
# File lib/rubygems/specification.rb, line 675 675: def add_development_dependency(gem, *requirements) 676: add_dependency_with_type(gem, :development, *requirements) 677: end
Adds a runtime dependency to this Gem. For example,
spec.add_runtime_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 685 685: def add_runtime_dependency(gem, *requirements) 686: add_dependency_with_type(gem, :runtime, *requirements) 687: 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 583 583: def assign_defaults 584: @@nil_attributes.each do |name| 585: instance_variable_set name, nil 586: end 587: 588: @@non_nil_attributes.each do |name, default| 589: value = case default 590: when Time, Numeric, Symbol, true, false, nil then default 591: else default.dup 592: end 593: 594: instance_variable_set name, value 595: end 596: 597: # HACK 598: instance_variable_set :@new_platform, Gem::Platform::RUBY 599: 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 987 987: def dependent_gems 988: out = [] 989: Gem.source_index.each do |name,gem| 990: gem.dependencies.each do |dep| 991: if self.satisfies_requirement?(dep) then 992: sats = [] 993: find_all_satisfiers(dep) do |sat| 994: sats << sat 995: end 996: out << [gem, dep, sats] 997: end 998: end 999: end 1000: out 1001: end
# File lib/rubygems/specification.rb, line 368 368: def development_dependencies 369: dependencies.select { |d| d.type == :development } 370: end
The default (generated) file name of the gem.
# File lib/rubygems/specification.rb, line 726 726: def file_name 727: full_name + ".gem" 728: end
# File lib/rubygems/specification.rb, line 1025 1025: def find_all_satisfiers(dep) 1026: Gem.source_index.each do |name,gem| 1027: if(gem.satisfies_requirement?(dep)) then 1028: yield gem 1029: end 1030: end 1031: 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 695 695: def full_name 696: if platform == Gem::Platform::RUBY or platform.nil? then 697: "#{@name}-#{@version}" 698: else 699: "#{@name}-#{@version}-#{platform}" 700: end 701: end
The directory that this gem was installed into.
# File lib/rubygems/specification.rb, line 733 733: def installation_path 734: path = File.dirname(@loaded_from).split(File::SEPARATOR)[0..-2] 735: path = path.join File::SEPARATOR 736: File.expand_path path 737: end
Predicates ——————————————————
# File lib/rubygems/specification.rb, line 555 555: def loaded?; @loaded ? true : false ; end
Sets the rubygems_version to Gem::RubyGemsVersion.
# File lib/rubygems/specification.rb, line 652 652: def mark_version 653: @rubygems_version = RubyGemsVersion 654: 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 969 969: def normalize 970: if defined?(@extra_rdoc_files) and @extra_rdoc_files then 971: @extra_rdoc_files.uniq! 972: @files ||= [] 973: @files.concat(@extra_rdoc_files) 974: end 975: @files.uniq! if @files 976: end
Return a string containing a Ruby code representation of the given object.
# File lib/rubygems/specification.rb, line 1035 1035: def ruby_code(obj) 1036: case obj 1037: when String then '%q{' + obj + '}' 1038: when Array then obj.inspect 1039: when Gem::Version then obj.to_s.inspect 1040: when Date then '%q{' + obj.strftime('%Y-%m-%d') + '}' 1041: when Time then '%q{' + obj.strftime('%Y-%m-%d') + '}' 1042: when Numeric then obj.inspect 1043: when true, false, nil then obj.inspect 1044: when Gem::Platform then "Gem::Platform.new(#{obj.to_a.inspect})" 1045: when Gem::Requirement then "Gem::Requirement.new(#{obj.to_s.inspect})" 1046: else raise Exception, "ruby_code case not handled: #{obj.class}" 1047: end 1048: end
# File lib/rubygems/specification.rb, line 364 364: def runtime_dependencies 365: dependencies.select { |d| d.type == :runtime || d.type == nil } 366: end
# File lib/rubygems/specification.rb, line 767 767: def same_attributes?(other) 768: @@attributes.each do |name, default| 769: return false unless self.send(name) == other.send(name) 770: end 771: true 772: 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 745 745: def satisfies_requirement?(dependency) 746: return @name == dependency.name && 747: dependency.version_requirements.satisfied_by?(@version) 748: end
Comparison methods ———————————————
# File lib/rubygems/specification.rb, line 752 752: def sort_obj 753: [@name, @version.to_ints, @new_platform == Gem::Platform::RUBY ? -1 : 1] 754: end
DEPRECATED gemspec attributes ———————————-
# File lib/rubygems/specification.rb, line 381 381: def test_suite_file 382: warn 'test_suite_file deprecated, use test_files' 383: test_files.first 384: end
# File lib/rubygems/specification.rb, line 386 386: def test_suite_file=(val) 387: warn 'test_suite_file= deprecated, use test_files=' 388: @test_files = [] unless defined? @test_files 389: @test_files << val 390: 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 825 825: def to_ruby 826: mark_version 827: result = [] 828: result << "Gem::Specification.new do |s|" 829: 830: result << " s.name = #{ruby_code name}" 831: result << " s.version = #{ruby_code version}" 832: unless platform.nil? or platform == Gem::Platform::RUBY then 833: result << " s.platform = #{ruby_code original_platform}" 834: end 835: result << "" 836: result << " s.required_rubygems_version = #{ruby_code required_rubygems_version} if s.respond_to? :required_rubygems_version=" 837: 838: handled = [ 839: :dependencies, 840: :name, 841: :platform, 842: :required_rubygems_version, 843: :specification_version, 844: :version, 845: ] 846: 847: attributes = @@attributes.sort_by { |attr_name,| attr_name.to_s } 848: 849: attributes.each do |attr_name, default| 850: next if handled.include? attr_name 851: current_value = self.send(attr_name) 852: if current_value != default or 853: self.class.required_attribute? attr_name then 854: result << " s.#{attr_name} = #{ruby_code current_value}" 855: end 856: end 857: 858: result << nil 859: result << " if s.respond_to? :specification_version then" 860: result << " current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION" 861: result << " s.specification_version = #{specification_version}" 862: result << nil 863: 864: result << " if current_version >= 3 then" 865: 866: unless dependencies.empty? then 867: dependencies.each do |dep| 868: version_reqs_param = dep.requirements_list.inspect 869: dep.instance_variable_set :@type, :runtime if dep.type.nil? # HACK 870: result << " s.add_#{dep.type}_dependency(%q<#{dep.name}>, #{version_reqs_param})" 871: end 872: end 873: 874: result << " else" 875: 876: unless dependencies.empty? then 877: dependencies.each do |dep| 878: version_reqs_param = dep.requirements_list.inspect 879: result << " s.add_dependency(%q<#{dep.name}>, #{version_reqs_param})" 880: end 881: end 882: 883: result << ' end' 884: 885: result << " else" 886: dependencies.each do |dep| 887: version_reqs_param = dep.requirements_list.inspect 888: result << " s.add_dependency(%q<#{dep.name}>, #{version_reqs_param})" 889: end 890: result << " end" 891: 892: result << "end" 893: result << nil 894: 895: result.join "\n" 896: end
# File lib/rubygems/specification.rb, line 1003 1003: def to_s 1004: "#<Gem::Specification name=#{@name} version=#{@version}>" 1005: 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 905 905: def validate 906: extend Gem::UserInteraction 907: 908: normalize 909: 910: if rubygems_version != RubyGemsVersion then 911: raise Gem::InvalidSpecificationException, 912: "expected RubyGems version #{RubyGemsVersion}, was #{rubygems_version}" 913: end 914: 915: @@required_attributes.each do |symbol| 916: unless self.send symbol then 917: raise Gem::InvalidSpecificationException, 918: "missing value for attribute #{symbol}" 919: end 920: end 921: 922: if require_paths.empty? then 923: raise Gem::InvalidSpecificationException, 924: "specification must have at least one require_path" 925: end 926: 927: case platform 928: when Gem::Platform, Platform::RUBY then # ok 929: else 930: raise Gem::InvalidSpecificationException, 931: "invalid platform #{platform.inspect}, see Gem::Platform" 932: end 933: 934: unless Array === authors and 935: authors.all? { |author| String === author } then 936: raise Gem::InvalidSpecificationException, 937: 'authors must be Array of Strings' 938: end 939: 940: # Warnings 941: 942: %w[author email homepage rubyforge_project summary].each do |attribute| 943: value = self.send attribute 944: alert_warning "no #{attribute} specified" if value.nil? or value.empty? 945: end 946: 947: alert_warning "RDoc will not be generated (has_rdoc == false)" unless 948: has_rdoc 949: 950: alert_warning "deprecated autorequire specified" if autorequire 951: 952: executables.each do |executable| 953: executable_path = File.join bindir, executable 954: shebang = File.read(executable_path, 2) == '#!' 955: 956: alert_warning "#{executable_path} is missing #! line" unless shebang 957: end 958: 959: true 960: end