diff options
author | ryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-03-01 09:41:32 +0000 |
---|---|---|
committer | ryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-03-01 09:41:32 +0000 |
commit | 25a9b62d45ddd60a231272567c7dda9337da9b62 (patch) | |
tree | e72ba4c9c01cba5fb510eb1eafaba76d998baf4c /lib/rubygems/specification.rb | |
parent | 86bb0af7ea3b50f72e6845a6f5f64cb1b23fd279 (diff) | |
download | ruby-25a9b62d45ddd60a231272567c7dda9337da9b62.tar.gz |
Import rubygems 1.6.0 (released version @ 58d8a0b9)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/specification.rb')
-rw-r--r-- | lib/rubygems/specification.rb | 83 |
1 files changed, 64 insertions, 19 deletions
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index f66288498b..a5e250a5df 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -339,7 +339,8 @@ class Gem::Specification # List of dependencies that will automatically be activated at runtime. def runtime_dependencies - dependencies.select { |d| d.type == :runtime || d.type == nil } + # TODO: fix #type to return :runtime if nil + dependencies.select { |d| d.type == :runtime } end ## @@ -542,8 +543,8 @@ class Gem::Specification def self.normalize_yaml_input(input) result = input.respond_to?(:read) ? input.read : input - result = "--- " + result unless result =~ /^--- / - result + result = "--- " + result unless result =~ /\A--- / + result.gsub(/ !!null \n/, " \n") end ## @@ -685,6 +686,14 @@ class Gem::Specification alias eql? == # :nodoc: ## + # A macro to yield cached gem path + # + def cache_gem + cache_name = File.join(Gem.dir, 'cache', file_name) + return File.exist?(cache_name) ? cache_name : nil + end + + ## # True if this gem has the same attributes as +other+. def same_attributes?(other) @@ -726,11 +735,13 @@ class Gem::Specification end def to_yaml(opts = {}) # :nodoc: - return super if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck? - - YAML.quick_emit object_id, opts do |out| - out.map taguri, to_yaml_style do |map| - encode_with map + if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck? then + super.gsub(/ !!null \n/, " \n") + else + YAML.quick_emit object_id, opts do |out| + out.map taguri, to_yaml_style do |map| + encode_with map + end end end end @@ -795,21 +806,17 @@ class Gem::Specification result << " if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then" - unless dependencies.empty? then - dependencies.each do |dep| - version_reqs_param = dep.requirements_list.inspect - dep.instance_variable_set :@type, :runtime if dep.type.nil? # HACK - result << " s.add_#{dep.type}_dependency(%q<#{dep.name}>, #{version_reqs_param})" - end + dependencies.each do |dep| + req = dep.requirements_list.inspect + dep.instance_variable_set :@type, :runtime if dep.type.nil? # HACK + result << " s.add_#{dep.type}_dependency(%q<#{dep.name}>, #{req})" end result << " else" - unless dependencies.empty? then - dependencies.each do |dep| - version_reqs_param = dep.requirements_list.inspect - result << " s.add_dependency(%q<#{dep.name}>, #{version_reqs_param})" - end + dependencies.each do |dep| + version_reqs_param = dep.requirements_list.inspect + result << " s.add_dependency(%q<#{dep.name}>, #{version_reqs_param})" end result << ' end' @@ -827,6 +834,15 @@ class Gem::Specification result.join "\n" end + def to_ruby_for_cache + s = dup + # remove large blobs that aren't used at runtime: + s.files = nil + s.extra_rdoc_files = nil + s.rdoc_options = nil + s.to_ruby + end + ## # Checks that the specification contains all required fields, and does a # very basic sanity check. @@ -835,6 +851,7 @@ class Gem::Specification # checks.. def validate + require 'rubygems/user_interaction' extend Gem::UserInteraction normalize @@ -1523,4 +1540,32 @@ class Gem::Specification @extensions, ].flatten.uniq.compact end + + def conflicts + conflicts = {} + Gem.loaded_specs.values.each do |spec| + bad = self.runtime_dependencies.find_all { |dep| + spec.name == dep.name and not spec.satisfies_requirement? dep + } + + conflicts[spec] = bad unless bad.empty? + end + conflicts + end + + def traverse trail = [], &b + trail = trail + [self] + runtime_dependencies.each do |dep| + dep_specs = Gem.source_index.search dep, true + dep_specs.each do |dep_spec| + b[self, dep, dep_spec, trail + [dep_spec]] + dep_spec.traverse(trail, &b) unless + trail.map(&:name).include? dep_spec.name + end + end + end + + def dependent_specs + runtime_dependencies.map { |dep| Gem.source_index.search dep, true }.flatten + end end |