Permalink
Browse files

Factor out Bundler.load_gemspec so Source::Path and GemHelper can use it

  • Loading branch information...
1 parent 838b567 commit 681a5cb929560c4b629b74b5d4e8868e2ceaaead @indirect indirect committed Aug 15, 2010
Showing with 28 additions and 26 deletions.
  1. +26 −0 lib/bundler.rb
  2. +1 −2 lib/bundler/gem_helper.rb
  3. +1 −24 lib/bundler/source.rb
View
@@ -208,6 +208,32 @@ def sudo(str)
`sudo -p 'Enter your password to install the bundled RubyGems to your system: ' #{str}`
end
+ def load_gemspec(file)
+ path = Pathname.new(file)
+ # Eval the gemspec from its parent directory
+ Dir.chdir(path.dirname) do
+ begin
+ Gem::Specification.from_yaml(path.basename)
+ # Raises ArgumentError if the file is not valid YAML
+ rescue ArgumentError, SyntaxError, Gem::EndOfYAMLException, Gem::Exception
+ begin
+ eval(File.read(path.basename), TOPLEVEL_BINDING, path.expand_path.to_s)
+ rescue LoadError => e
+ original_line = e.backtrace.find { |line| line.include?(path.to_s) }
+ msg = "There was a LoadError while evaluating #{path.basename}:\n #{e.message}"
+ msg << " from\n #{original_line}" if original_line
+ msg << "\n"
+
+ if RUBY_VERSION >= "1.9.0"
+ msg << "\nDoes it try to require a relative path? That doesn't work in Ruby 1.9."
+ end
+
+ raise GemspecError, msg
+ end
+ end
+ end
+ end
+
private
def configure_gem_home_and_path
@@ -69,8 +69,7 @@ def built_gem_path
def determine_name
gemspecs = Dir[File.join(base, "*.gemspec")]
raise "Unable to determine name from existing gemspec." unless gemspecs.size == 1
-
- Gem::Specification.load(File.join(base, File.basename(gemspecs.first)[/^.*\.gemspec$/])).name
+ Bundler.load_gemspec(gemspecs.first).name
end
def git_push
View
@@ -322,30 +322,7 @@ def load_spec_files
if File.directory?(path)
Dir["#{path}/#{@glob}"].each do |file|
- file = Pathname.new(file)
- # Eval the gemspec from its parent directory
- spec = Dir.chdir(file.dirname) do
- begin
- Gem::Specification.from_yaml(file.basename)
- # Raises ArgumentError if the file is not valid YAML
- rescue ArgumentError, SyntaxError, Gem::EndOfYAMLException, Gem::Exception
- begin
- eval(File.read(file.basename), TOPLEVEL_BINDING, file.expand_path.to_s)
- rescue LoadError => e
- original_line = e.backtrace.find { |line| line.include?(file.to_s) }
- msg = "There was a LoadError while evaluating #{file.basename}:\n #{e.message}"
- msg << " from\n #{original_line}" if original_line
- msg << "\n"
-
- if RUBY_VERSION >= "1.9.0"
- msg << "\nDoes it try to require a relative path? That doesn't work in Ruby 1.9."
- end
-
- raise GemspecError, msg
- end
- end
- end
-
+ spec = Bundler.load_gemspec(file)
if spec
spec.loaded_from = file.to_s
spec.source = self

0 comments on commit 681a5cb

Please sign in to comment.