diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-26 20:24:51 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-26 20:24:51 +0000 |
commit | e487a7f53cffbadf0bf15ff169c9cb5898503250 (patch) | |
tree | eaa80eb4ced6fcdcc8b327d1cc5e47f66703fd1b /lib/rubygems/basic_specification.rb | |
parent | cddd93a57568966b416e300529bdffc0c7e87b51 (diff) | |
download | ruby-e487a7f53cffbadf0bf15ff169c9cb5898503250.tar.gz |
* lib/rubygems: Import RubyGems 2.1.0 Release Candidate
* test/rubygems: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42693 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/basic_specification.rb')
-rw-r--r-- | lib/rubygems/basic_specification.rb | 220 |
1 files changed, 112 insertions, 108 deletions
diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb index 2e47f32986..24bb4bc014 100644 --- a/lib/rubygems/basic_specification.rb +++ b/lib/rubygems/basic_specification.rb @@ -1,139 +1,143 @@ -module Gem - # BasicSpecification is an abstract class which implements some common code used by - # both Specification and StubSpecification. - class BasicSpecification - def self.default_specifications_dir - File.join(Gem.default_dir, "specifications", "default") - end +## +# BasicSpecification is an abstract class which implements some common code +# used by both Specification and StubSpecification. - ## - # Name of the gem +class Gem::BasicSpecification - def name - raise NotImplementedError - end + ## + # The path this gemspec was loaded from. This attribute is not persisted. - ## - # Version of the gem + attr_reader :loaded_from - def version - raise NotImplementedError - end + def self.default_specifications_dir + File.join(Gem.default_dir, "specifications", "default") + end - ## - # Platform of the gem + ## + # True when the gem has been activated - def platform - raise NotImplementedError - end + def activated? + raise NotImplementedError + end - ## - # Require paths of the gem + ## + # Returns the full path to the base gem directory. + # + # eg: /usr/local/lib/ruby/gems/1.8 + + def base_dir + return Gem.dir unless loaded_from + @base_dir ||= if default_gem? then + File.dirname File.dirname File.dirname loaded_from + else + File.dirname File.dirname loaded_from + end + end - def require_paths - raise NotImplementedError - end + ## + # Return true if this spec can require +file+. - ## - # True when the gem has been activated + def contains_requirable_file? file + root = full_gem_path + suffixes = Gem.suffixes - def activated? - raise NotImplementedError + require_paths.any? do |lib| + base = "#{root}/#{lib}/#{file}" + suffixes.any? { |suf| File.file? "#{base}#{suf}" } end + end - ## - # Return a Gem::Specification from this gem + def default_gem? + loaded_from && + File.dirname(loaded_from) == self.class.default_specifications_dir + end - def to_spec - raise NotImplementedError - end + def find_full_gem_path # :nodoc: + # TODO: also, shouldn't it default to full_name if it hasn't been written? + path = File.expand_path File.join(gems_dir, full_name) + path.untaint + path if File.directory? path + end + + private :find_full_gem_path - ## - # The filename of the gem specification - attr_reader :filename + ## + # The full path to the gem (install path + full name). - ## - # Set the filename of the Specification was loaded from. +path+ is converted - # to a String. + def full_gem_path + # TODO: This is a heavily used method by gems, so we'll need + # to aleast just alias it to #gem_dir rather than remove it. + @full_gem_path ||= find_full_gem_path + end - def filename= path - @filename = path && path.to_s + ## + # 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. - @full_gem_path = nil - @gems_dir = nil - @base_dir = nil + def full_name + if platform == Gem::Platform::RUBY or platform.nil? then + "#{name}-#{version}".untaint + else + "#{name}-#{version}-#{platform}".untaint end + end - ## - # Return true if this spec can require +file+. + ## + # Returns the full path to the gems directory containing this spec's + # gem directory. eg: /usr/local/lib/ruby/1.8/gems - def contains_requirable_file? file - root = full_gem_path - suffixes = Gem.suffixes + def gems_dir + # TODO: this logic seems terribly broken, but tests fail if just base_dir + @gems_dir ||= File.join(loaded_from && base_dir || Gem.dir, "gems") + end - require_paths.any? do |lib| - base = "#{root}/#{lib}/#{file}" - suffixes.any? { |suf| File.file? "#{base}#{suf}" } - end - end + ## + # Set the path the Specification was loaded from. +path+ is converted to a + # String. - ## - # The full path to the gem (install path + full name). + def loaded_from= path + @loaded_from = path && path.to_s - def full_gem_path - # TODO: This is a heavily used method by gems, so we'll need - # to aleast just alias it to #gem_dir rather than remove it. - @full_gem_path ||= find_full_gem_path - end + @full_gem_path = nil + @gems_dir = nil + @base_dir = nil + end - # :nodoc: - def find_full_gem_path - # TODO: also, shouldn't it default to full_name if it hasn't been written? - path = File.expand_path File.join(gems_dir, full_name) - path.untaint - path if File.directory? path - end - private :find_full_gem_path + ## + # Name of the gem - ## - # Returns the full path to the gems directory containing this spec's - # gem directory. eg: /usr/local/lib/ruby/1.8/gems + def name + raise NotImplementedError + end - def gems_dir - # TODO: this logic seems terribly broken, but tests fail if just base_dir - @gems_dir ||= File.join(filename && base_dir || Gem.dir, "gems") - end + ## + # Platform of the gem - ## - # Returns the full path to the base gem directory. - # - # eg: /usr/local/lib/ruby/gems/1.8 - - def base_dir - return Gem.dir unless filename - @base_dir ||= if default_gem? then - File.dirname File.dirname File.dirname filename - else - File.dirname File.dirname filename - end - end + def platform + raise NotImplementedError + end - def default_gem? - filename && - File.dirname(filename) == self.class.default_specifications_dir - end + ## + # Require paths of the gem - ## - # 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. - - def full_name - if platform == Gem::Platform::RUBY or platform.nil? then - "#{name}-#{version}".untaint - else - "#{name}-#{version}-#{platform}".untaint - end - end + def require_paths + raise NotImplementedError end + + ## + # Return a Gem::Specification from this gem + + def to_spec + raise NotImplementedError + end + + ## + # Version of the gem + + def version + raise NotImplementedError + end + end + |