aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/stub_specification.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-26 20:24:51 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-26 20:24:51 +0000
commite487a7f53cffbadf0bf15ff169c9cb5898503250 (patch)
treeeaa80eb4ced6fcdcc8b327d1cc5e47f66703fd1b /lib/rubygems/stub_specification.rb
parentcddd93a57568966b416e300529bdffc0c7e87b51 (diff)
downloadruby-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/stub_specification.rb')
-rw-r--r--lib/rubygems/stub_specification.rb185
1 files changed, 93 insertions, 92 deletions
diff --git a/lib/rubygems/stub_specification.rb b/lib/rubygems/stub_specification.rb
index c2910c1bba..08102b48ef 100644
--- a/lib/rubygems/stub_specification.rb
+++ b/lib/rubygems/stub_specification.rb
@@ -1,119 +1,120 @@
-module Gem
- # Gem::StubSpecification reads the stub: line from the gemspec
- # This prevents us having to eval the entire gemspec in order to
- # find out certain information.
- class StubSpecification < BasicSpecification
- # :nodoc:
- PREFIX = "# stub: "
-
- OPEN_MODE = # :nodoc:
- if Object.const_defined? :Encoding then
- 'r:UTF-8:-'
- else
- 'r'
- end
-
- # :nodoc:
- class StubLine
- attr_reader :parts
+##
+# Gem::StubSpecification reads the stub: line from the gemspec. This prevents
+# us having to eval the entire gemspec in order to find out certain
+# information.
+
+class Gem::StubSpecification < Gem::BasicSpecification
+ # :nodoc:
+ PREFIX = "# stub: "
+
+ OPEN_MODE = # :nodoc:
+ if Object.const_defined? :Encoding then
+ 'r:UTF-8:-'
+ else
+ 'r'
+ end
- def initialize(data)
- @parts = data[PREFIX.length..-1].split(" ")
- end
+ class StubLine # :nodoc: all
+ attr_reader :parts
- def name
- @parts[0]
- end
+ def initialize(data)
+ @parts = data[PREFIX.length..-1].split(" ")
+ end
- def version
- Gem::Version.new @parts[1]
- end
+ def name
+ @parts[0]
+ end
- def platform
- Gem::Platform.new @parts[2]
- end
+ def version
+ Gem::Version.new @parts[1]
+ end
- def require_paths
- @parts[3..-1].join(" ").split("\0")
- end
+ def platform
+ Gem::Platform.new @parts[2]
end
- def initialize(filename)
- self.filename = filename
- @data = nil
- @spec = nil
+ def require_paths
+ @parts[3..-1].join(" ").split("\0")
end
+ end
- ##
- # Name of the gem
+ def initialize(filename)
+ self.loaded_from = filename
+ @data = nil
+ @spec = nil
+ end
- def name
- @name ||= data.name
- end
+ ##
+ # True when this gem has been activated
- ##
- # Version of the gem
+ def activated?
+ loaded = Gem.loaded_specs[name]
+ loaded && loaded.version == version
+ end
- def version
- @version ||= data.version
+ ##
+ # If the gemspec contains a stubline, returns a StubLine instance. Otherwise
+ # returns the full Gem::Specification.
+
+ def data
+ unless @data
+ open loaded_from, OPEN_MODE do |file|
+ begin
+ file.readline # discard encoding line
+ stubline = file.readline.chomp
+ @data = StubLine.new(stubline) if stubline.start_with?(PREFIX)
+ rescue EOFError
+ end
+ end
end
- ##
- # Platform of the gem
+ @data ||= to_spec
+ end
- def platform
- @platform ||= data.platform
- end
+ private :data
- ##
- # Require paths of the gem
+ ##
+ # Name of the gem
- def require_paths
- @require_paths ||= data.require_paths
- end
+ def name
+ @name ||= data.name
+ end
- ##
- # The full Gem::Specification for this gem, loaded from evalling its gemspec
+ ##
+ # Platform of the gem
- def to_spec
- @spec ||= Gem::Specification.load(filename)
- end
+ def platform
+ @platform ||= data.platform
+ end
- ##
- # True when this gem has been activated
+ ##
+ # Require paths of the gem
- def activated?
- loaded = Gem.loaded_specs[name]
- loaded && loaded.version == version
- end
+ def require_paths
+ @require_paths ||= data.require_paths
+ end
- ##
- # Is this StubSpecification valid? i.e. have we found a stub line, OR does
- # the filename contain a valid gemspec?
+ ##
+ # The full Gem::Specification for this gem, loaded from evalling its gemspec
- def valid?
- data
- end
+ def to_spec
+ @spec ||= Gem::Specification.load(loaded_from)
+ end
- private
-
- ##
- # If the gemspec contains a stubline, returns a StubLine instance. Otherwise
- # returns the full Gem::Specification.
-
- def data
- unless @data
- open filename, OPEN_MODE do |file|
- begin
- file.readline # discard encoding line
- stubline = file.readline.chomp
- @data = StubLine.new(stubline) if stubline.start_with?(PREFIX)
- rescue EOFError
- end
- end
- end
+ ##
+ # Is this StubSpecification valid? i.e. have we found a stub line, OR does
+ # the filename contain a valid gemspec?
- @data ||= to_spec
- end
+ def valid?
+ data
end
+
+ ##
+ # Version of the gem
+
+ def version
+ @version ||= data.version
+ end
+
end
+